Re: [Tutor] regular expression query

2019-06-09 Thread Cameron Simpson
On 08Jun2019 22:27, Sean Murphy wrote: Windows 10 OS, Python 3.6 Thanks for this. I have a couple of queries in relation to extracting content using regular expressions. I understand [...the regexp syntax...] The challenge I am finding is getting a pattern to extract specific word(s). Try

[Tutor] regular expression query

2019-06-08 Thread mhysnm1964
Hello all, Windows 10 OS, Python 3.6 I have a couple of queries in relation to extracting content using regular expressions. I understand the pattern chars (.?*+), Meta-chars \d, \D, \W, \W and so on. The class structure [.]. The group I believe I understand (.). The repeat feature {m,n}.

Re: [Tutor] (regular expression)

2016-12-10 Thread Martin A. Brown
Hello Isaac, This second posting you have made has provided more information about what you are trying to accomplish and how (and also was readable, where the first one looked like it got mangled by your mail user agent; it's best to try to post only plain text messages to this sort of mailin

Re: [Tutor] (regular expression)

2016-12-10 Thread isaac tetteh
this is the real code with urllib.request.urlopen("https://www.sdstate.edu/electrical-engineering-and-computer-science";) as cs: cs_page = cs.read() soup = BeautifulSoup(cs_page, "html.parser") print(len(soup.body.find_all(string = ["Engineering","engineering"]))) i used control +

Re: [Tutor] Regular expression on python

2015-04-15 Thread Alan Gauld
On 15/04/15 09:24, Peter Otten wrote: function call. I've never seen (or noticed?) the embedded form, and don't see it described in the docs anywhere Quoting : """ (?aiLmsux) (One or more letters from the set 'a', 'i', 'L', 'm', 's', 'u', 'x'.) The

Re: [Tutor] Regular expression on python

2015-04-15 Thread Peter Otten
Albert-Jan Roskam wrote: > On Tue, 4/14/15, Peter Otten <__pete...@web.de> wrote: >>> >>> pprint.pprint( >>> ... [(k, int(v)) for k, v in >>> ... >re.compile(r"(.+?):\s+(\d+)(?:\s+\(.*?\))?\s*").findall(line)]) >>> [('Input Read Pairs', 2127436), >>>('Both Surviving', 1795091), >>>('Forward Only

Re: [Tutor] Regular expression on python

2015-04-15 Thread Albert-Jan Roskam
On Tue, 4/14/15, Peter Otten <__pete...@web.de> wrote: Subject: Re: [Tutor] Regular expression on python To: tutor@python.org Date: Tuesday, April 14, 2015, 4:37 PM Steven D'Aprano wrote: > On Tue, Apr 14, 2015 at 10:00:47AM +020

Re: [Tutor] Regular expression on python

2015-04-15 Thread Peter Otten
Alan Gauld wrote: > On 15/04/15 02:02, Steven D'Aprano wrote: >>> New one on me. Where does one find out about verbose mode? >>> I don't see it in the re docs? >>> > >> or embed the flag in the pattern. The flags that I know of are: >> >> (?x) re.X re.VERBOSE >> >> The flag can appear anywhere in

Re: [Tutor] Regular expression on python

2015-04-15 Thread Alan Gauld
On 15/04/15 02:02, Steven D'Aprano wrote: New one on me. Where does one find out about verbose mode? I don't see it in the re docs? or embed the flag in the pattern. The flags that I know of are: (?x) re.X re.VERBOSE The flag can appear anywhere in the pattern and applies to the whole patte

Re: [Tutor] Regular expression on python

2015-04-14 Thread Alex Kleider
On 2015-04-14 16:49, Alan Gauld wrote: New one on me. Where does one find out about verbose mode? I don't see it in the re docs? This is where I go whenever I find myself having to (re)learn the details of regex: https://docs.python.org/3/howto/regex.html I believe a '2' can be substituted

Re: [Tutor] Regular expression on python

2015-04-14 Thread Steven D'Aprano
On Wed, Apr 15, 2015 at 12:49:26AM +0100, Alan Gauld wrote: > New one on me. Where does one find out about verbose mode? > I don't see it in the re docs? > > I see an re.X flag but while it seems to be similar in purpose > yet it is different to your style above (no parens for example)? I presum

Re: [Tutor] Regular expression on python

2015-04-14 Thread Mark Lawrence
On 15/04/2015 00:49, Alan Gauld wrote: On 14/04/15 13:21, Steven D'Aprano wrote: although I would probably want to write it out in verbose mode just in case the requirements did change: r"""(?x)(?# verbose mode) (.+?): (?# capture one or more character, followed by a colon) \s+

Re: [Tutor] Regular expression on python

2015-04-14 Thread Alan Gauld
On 14/04/15 13:21, Steven D'Aprano wrote: although I would probably want to write it out in verbose mode just in case the requirements did change: r"""(?x)(?# verbose mode) (.+?): (?# capture one or more character, followed by a colon) \s+ (?# one or more whitespace) (\

Re: [Tutor] Regular expression on python

2015-04-14 Thread Peter Otten
Steven D'Aprano wrote: > On Tue, Apr 14, 2015 at 10:00:47AM +0200, Peter Otten wrote: >> Steven D'Aprano wrote: > >> > I swear that Perl has been a blight on an entire generation of >> > programmers. All they know is regular expressions, so they turn every >> > data processing problem into a regu

Re: [Tutor] Regular expression on python

2015-04-14 Thread Steven D'Aprano
On Tue, Apr 14, 2015 at 10:00:47AM +0200, Peter Otten wrote: > Steven D'Aprano wrote: > > I swear that Perl has been a blight on an entire generation of > > programmers. All they know is regular expressions, so they turn every > > data processing problem into a regular expression. Or at least they

Re: [Tutor] Regular expression on python

2015-04-14 Thread Peter Otten
Steven D'Aprano wrote: > On Mon, Apr 13, 2015 at 02:29:07PM +0200, jarod...@libero.it wrote: >> Dear all. >> I would like to extract from some file some data. >> The line I'm interested is this: >> >> Input Read Pairs: 2127436 Both Surviving: 1795091 (84.38%) Forward >> Only Surviving: 17315 (0.8

Re: [Tutor] Regular expression on python

2015-04-13 Thread Steven D'Aprano
On Mon, Apr 13, 2015 at 02:29:07PM +0200, jarod...@libero.it wrote: > Dear all. > I would like to extract from some file some data. > The line I'm interested is this: > > Input Read Pairs: 2127436 Both Surviving: 1795091 (84.38%) Forward > Only Surviving: 17315 (0.81%) Reverse Only Surviving: 641

Re: [Tutor] Regular expression on python

2015-04-13 Thread Alan Gauld
On 13/04/15 19:42, Alan Gauld wrote: if lines.startswith("Input"): tp = lines.split("\t") print re.findall("Input\d",str(tp)) Input is not followed by a number. You need a more powerful pattern. Which is why I recommend trying to solve it as far as possible w

Re: [Tutor] Regular expression on python

2015-04-13 Thread Alan Gauld
On 13/04/15 13:29, jarod...@libero.it wrote: Input Read Pairs: 2127436 Both Surviving: 1795091 (84.38%) Forward Only Surviving: 17315 (0.81%) Reverse Only Surviving: 6413 (0.30%) Dropped: 308617 (14.51%) Its not clear where the tabs are in this line. But if they are after the numbers, like s

[Tutor] Regular expression on python

2015-04-13 Thread jarod...@libero.it
Dear all. I would like to extract from some file some data. The line I'm interested is this: Input Read Pairs: 2127436 Both Surviving: 1795091 (84.38%) Forward Only Surviving: 17315 (0.81%) Reverse Only Surviving: 6413 (0.30%) Dropped: 308617 (14.51%) with open("255.trim.log","r") as p:

Re: [Tutor] Regular expression

2014-09-23 Thread Steven D'Aprano
On Tue, Sep 23, 2014 at 11:40:25AM +0200, jarod...@libero.it wrote: > Hi there!! > > I need to read this file: > > pippo.count : > 10566 ZXDC >2900 ZYG11A >7909 ZYG11B >3584 ZYX >9614 ZZEF1 > 17704 ZZZ3 > How can extract only the number and the work in array? Thanks for any he

[Tutor] Regular expression

2014-09-23 Thread jarod...@libero.it
Hi there!! I need to read this file: pippo.count : 10566 ZXDC 2900 ZYG11A 7909 ZYG11B 3584 ZYX 9614 ZZEF1 17704 ZZZ3 This file present a use space on the begin then they have a number and the a word. p =re.compile("\s+\d+") with open("pippo.count") as p: for i in p:

Re: [Tutor] Regular expression - I

2014-02-18 Thread Santosh Kumar
Thank you all. I got it. :) I need to read more between lines . On Wed, Feb 19, 2014 at 4:25 AM, spir wrote: > On 02/18/2014 08:39 PM, Zachary Ware wrote: > >> Hi Santosh, >> >> On Tue, Feb 18, 2014 at 9:52 AM, Santosh Kumar >> wrote: >> >>> >>> Hi All, >>> >>> If you notice the below example,

Re: [Tutor] Regular expression - I

2014-02-18 Thread spir
On 02/18/2014 08:39 PM, Zachary Ware wrote: Hi Santosh, On Tue, Feb 18, 2014 at 9:52 AM, Santosh Kumar wrote: Hi All, If you notice the below example, case I is working as expected. Case I: In [41]: string = "test" In [42]: re.match('',string).group() Out[42]: '' But why is the raw string

Re: [Tutor] Regular expression - I

2014-02-18 Thread Emile van Sebille
On 2/18/2014 11:42 AM, Mark Lawrence wrote: On 18/02/2014 18:03, Steve Willoughby wrote: Because the regular expression means “match an angle-bracket Please do not top post on this list. Appropriate trimming is also appreciated. Emile ___

Re: [Tutor] Regular expression - I

2014-02-18 Thread Albert-Jan Roskam
_ > From: Steve Willoughby >To: Santosh Kumar >Cc: python mail list >Sent: Tuesday, February 18, 2014 7:03 PM >Subject: Re: [Tutor] Regular expression - I > > >Because the regular expression means “match an angle-bracket character, &g

Re: [Tutor] Regular expression - I

2014-02-18 Thread S Tareq
does any one know how to use 2to3 program to convert 2.7 coding 3.X please i need help sorry  On Tuesday, 18 February 2014, 19:50, Zachary Ware wrote: On Tue, Feb 18, 2014 at 11:39 AM, Zachary Ware wrote: >    >>> '' >    '' > > The equivalent raw string is exactly the same in this case:

Re: [Tutor] Regular expression - I

2014-02-18 Thread Zachary Ware
On Tue, Feb 18, 2014 at 11:39 AM, Zachary Ware wrote: >>>> '' >'' > > The equivalent raw string is exactly the same in this case: > >>>> r'' >'' Oops, I mistyped both of these. The repr should be '' in both cases. Sorry for the confusion! -- Zach _

Re: [Tutor] Regular expression - I

2014-02-18 Thread Mark Lawrence
On 18/02/2014 18:03, Steve Willoughby wrote: Because the regular expression means “match an angle-bracket character, zero or more H characters, followed by a close angle-bracket character” and your string does not match that pattern. This is why it’s best to check that the match succeeded bef

Re: [Tutor] Regular expression - I

2014-02-18 Thread Zachary Ware
Hi Santosh, On Tue, Feb 18, 2014 at 9:52 AM, Santosh Kumar wrote: > > Hi All, > > If you notice the below example, case I is working as expected. > > Case I: > In [41]: string = "test" > > In [42]: re.match('',string).group() > Out[42]: '' > > But why is the raw string 'r' not working as expected

Re: [Tutor] Regular expression - I

2014-02-18 Thread Steve Willoughby
Because the regular expression means “match an angle-bracket character, zero or more H characters, followed by a close angle-bracket character” and your string does not match that pattern. This is why it’s best to check that the match succeeded before going ahead to call group() on the result

Re: [Tutor] Regular expression - I

2014-02-18 Thread Steve Willoughby
The problem is not the use of the raw string, but rather the regular expression inside it. In regular expressions, the * means that whatever appears before it may be repeated zero or more times. So if you say H* that means zero or more H’s in a row. I think you mean an H followed by any numbe

Re: [Tutor] Regular expression - I

2014-02-18 Thread Santosh Kumar
Steve, i am trying to under r - raw string notation. Am i understanding it wrong. Rather than using "\", it says we can use the "r" option. http://docs.python.org/2/library/re.html Check the first paragraph for the above link. Thanks, santosh On Tue, Feb 18, 2014 at 11:33 PM, Steve Willoughb

[Tutor] Regular expression - I

2014-02-18 Thread Santosh Kumar
Hi All, If you notice the below example, case I is working as expected. Case I: In [41]: string = "test" In [42]: re.match('',string).group() Out[42]: '' But why is the raw string 'r' not working as expected ? Case II: In [43]: re.match(r'',string).group()

Re: [Tutor] regular expression wildcard search

2012-12-11 Thread Alan Gauld
On 11/12/12 15:54, Hs Hs wrote: myseq = 'MMSASRLAGTLIPAMAFLSCVRPESWEPC VEVVP NITYQCMELNFYKIPDNLPFSTKNLDLSFNPLRHLGSYSFFSFPELQVLDLSRCEIQTIED' if re.search('V*VVP',myseq): print myseq I hope this is just a typo but you are printing your original string not the things found... -- Alan G Autho

Re: [Tutor] regular expression wildcard search

2012-12-11 Thread Joel Goldstick
On Tue, Dec 11, 2012 at 10:54 AM, Hs Hs wrote: > Dear group: > Please send mail as plain text. It is easier to read > > I have 50 thousand lists. My aim is to search a pattern in the > alphabetical strings (these are protein sequence strings). > > > MMSASRLAGTLIPAMAFLSCVRPESWEPC VEVVP > NITYQC

Re: [Tutor] regular expression wildcard search

2012-12-11 Thread Emma Birath
Hi there Do you want your "*" to represent a single letter, or what is your intent? If you want only a single letter between the "V" and "VVP", use "\w" instead of "*". re.search('v\wVVP',myseq) Emma On Tue, Dec 11, 2012 at 8:54 AM, Hs Hs wrote: > Dear group: > > I have 50 thousand lists. My

[Tutor] regular expression wildcard search

2012-12-11 Thread Hs Hs
Dear group: I have 50 thousand lists. My aim is to search a pattern in the alphabetical strings (these are protein sequence strings). MMSASRLAGTLIPAMAFLSCVRPESWEPC VEVVP NITYQCMELNFYKIPDNLPFSTKNLDLSFNPLRHLGSYSFFSFPELQVLDLSRCEIQTIED my aim is to find the list of string that has V*VVP.  myseq

Re: [Tutor] Regular expression grouping insert thingy

2010-06-08 Thread Lang Hurst
Oh. Crap, I knew it would be something simple, but honestly, I don't think that I would have gotten there. Thank you so much. Seriously saved me more grey hair. Matthew Wood wrote: re.sub(r'(\d+)x', r'\1*x', input_text) -- I enjoy haiku but sometimes they don't make sense; refrigerator?

Re: [Tutor] Regular expression grouping insert thingy

2010-06-08 Thread Matthew Wood
re.sub(r'(\d+)x', r'\1*x', input_text) -- I enjoy haiku but sometimes they don't make sense; refrigerator? On Tue, Jun 8, 2010 at 10:11 PM, Lang Hurst wrote: > This is so trivial (or should be), but I can't figure it out. > > I'm trying to do what in vim is > > :s/\([0-9]\)x/\1*x/ > > That is

[Tutor] Regular expression grouping insert thingy

2010-06-08 Thread Lang Hurst
This is so trivial (or should be), but I can't figure it out. I'm trying to do what in vim is :s/\([0-9]\)x/\1*x/ That is, "find a number followed by an x and put a "*" in between the number and the x" So, if the string is "6443x - 3", I'll get back "6443*x - 3" I won't write down all the t

[Tutor] Regular expression generator

2010-02-24 Thread Kent Johnson
Another interesting tool - you give it a sample string and it helps you build a regular expression to match the string. This is not a regex tester, it actually creates the regex for you as you click on elements of the string. http://txt2re.com/index-python.php3 Kent ___

Re: [Tutor] regular expression question

2009-04-28 Thread Kent Johnson
On Tue, Apr 28, 2009 at 4:03 AM, Kelie wrote: > Hello, > > The following code returns 'abc123abc45abc789jk'. How do I revise the pattern > so > that the return value will be 'abc789jk'? In other words, I want to find the > pattern 'abc' that is closest to 'jk'. Here the string '123', '45' and '78

Re: [Tutor] regular expression question

2009-04-28 Thread Kent Johnson
2009/4/28 Marek spociń...@go2.pl,Poland : >> import re >> s = 'abc123abc45abc789jk' >> p = r'abc.+jk' >> lst = re.findall(p, s) >> print lst[0] > > I suggest using r'abc.+?jk' instead. > > the additional ? makes the preceeding '.+' non-greedy so instead of matching > as long string as it can it m

Re: [Tutor] regular expression question

2009-04-28 Thread Kelie
spir free.fr> writes: > To avoid that, use non-grouping parens (?:...). This also avoids the need for parens around the whole format: > p = Pattern(r'abc(?:(?!abc).)+jk') > print p.findall(s) > ['abc789jk'] > > Denis This one works! Thank you Denis. I'll try it out on the actual much longer (m

Re: [Tutor] regular expression question

2009-04-28 Thread Kelie
Andre Engels gmail.com> writes: > > 2009/4/28 Marek Spociński go2.pl,Poland 10g.pl>: > > I suggest using r'abc.+?jk' instead. > > > > That was my first idea too, but it does not work for this case, > because Python will still try to _start_ the match as soon as > possible. yeah, i tried t

Re: [Tutor] regular expression question

2009-04-28 Thread spir
Le Tue, 28 Apr 2009 11:06:16 +0200, Marek spociń...@go2.pl, Poland s'exprima ainsi: > > Hello, > > > > The following code returns 'abc123abc45abc789jk'. How do I revise the > > pattern so that the return value will be 'abc789jk'? In other words, I > > want to find the pattern 'abc' that is clos

Re: [Tutor] regular expression question

2009-04-28 Thread Marek Spociński , Poland
Dnia 28 kwietnia 2009 11:16 Andre Engels napisał(a): > 2009/4/28 Marek spociń...@go2.pl,Poland : > >> Hello, > >> > >> The following code returns 'abc123abc45abc789jk'. How do I revise the > >> pattern so > >> that the return value will be 'abc789jk'? In other words, I want to find > >> the > >>

Re: [Tutor] regular expression question

2009-04-28 Thread Andre Engels
2009/4/28 Marek spociń...@go2.pl,Poland : >> Hello, >> >> The following code returns 'abc123abc45abc789jk'. How do I revise the >> pattern so >> that the return value will be 'abc789jk'? In other words, I want to find the >> pattern 'abc' that is closest to 'jk'. Here the string '123', '45' and '7

Re: [Tutor] regular expression question

2009-04-28 Thread =?UTF-8?Q?Marek_Spoci=C5=84ski
> Hello, > > The following code returns 'abc123abc45abc789jk'. How do I revise the pattern > so > that the return value will be 'abc789jk'? In other words, I want to find the > pattern 'abc' that is closest to 'jk'. Here the string '123', '45' and '789' > are > just examples. They are actually q

[Tutor] regular expression question

2009-04-28 Thread Kelie
Hello, The following code returns 'abc123abc45abc789jk'. How do I revise the pattern so that the return value will be 'abc789jk'? In other words, I want to find the pattern 'abc' that is closest to 'jk'. Here the string '123', '45' and '789' are just examples. They are actually quite different in

Re: [Tutor] regular expression problem

2009-04-15 Thread Spencer Parker
After he said that...I realized where I was being dumb... On Wed, Apr 15, 2009 at 10:29 AM, bob gailer wrote: > Spencer Parker wrote: > >> I have a python script that takes a text file as an argument. It then >> loops >> through the text file pulling out specific lines of text that I want. I >

Re: [Tutor] regular expression problem

2009-04-15 Thread bob gailer
Spencer Parker wrote: I have a python script that takes a text file as an argument. It then loops through the text file pulling out specific lines of text that I want. I have a regular expression that evaluates the text to see if it matches a specific phrase. Right now I have it writing to an

[Tutor] regular expression problem

2009-04-15 Thread Spencer Parker
I have a python script that takes a text file as an argument. It then loops through the text file pulling out specific lines of text that I want. I have a regular expression that evaluates the text to see if it matches a specific phrase. Right now I have it writing to another text file that outp

Re: [Tutor] Regular expression oddity

2008-11-23 Thread spir
bob gailer a écrit : Emmanuel Ruellan wrote: Hi tutors! While trying to write a regular expression that would split a string the way I want, I noticed a behaviour I didn't expect. re.findall('.?', 'some text') ['s', 'o', 'm', 'e', ' ', 't', 'e', 'x', 't', ''] Where does the last

Re: [Tutor] Regular expression oddity

2008-11-22 Thread bob gailer
Emmanuel Ruellan wrote: Hi tutors! While trying to write a regular expression that would split a string the way I want, I noticed a behaviour I didn't expect. re.findall('.?', 'some text') ['s', 'o', 'm', 'e', ' ', 't', 'e', 'x', 't', ''] Where does the last string, the empty one

[Tutor] Regular expression oddity

2008-11-22 Thread Emmanuel Ruellan
Hi tutors! While trying to write a regular expression that would split a string the way I want, I noticed a behaviour I didn't expect. >>> re.findall('.?', 'some text') ['s', 'o', 'm', 'e', ' ', 't', 'e', 'x', 't', ''] Where does the last string, the empty one, come from? I find this behaviour r

Re: [Tutor] Regular expression to match \f in groff input?

2008-08-21 Thread Alan Gauld
"Bill Campbell" <[EMAIL PROTECTED]> wrote to get regular expressions to match the font change sequences in *roff input (e.g. \fB for bold, \fP to revert to previous font). The re library maps r'\f' to the single form-feed character (as it does other common single-character sequences like r'\n'

Re: [Tutor] Regular expression to match \f in groff input?

2008-08-21 Thread Danny Yoo
On Thu, Aug 21, 2008 at 1:40 PM, Bill Campbell <[EMAIL PROTECTED]> wrote: > I've been beating my head against the wall try to figure out how > to get regular expressions to match the font change sequences in > *roff input (e.g. \fB for bold, \fP to revert to previous font). > The re library maps r'

[Tutor] Regular expression to match \f in groff input?

2008-08-21 Thread Bill Campbell
I've been beating my head against the wall try to figure out how to get regular expressions to match the font change sequences in *roff input (e.g. \fB for bold, \fP to revert to previous font). The re library maps r'\f' to the single form-feed character (as it does other common single-character se

Re: [Tutor] Regular Expression

2007-12-21 Thread Michael Langford
You need to pass a parameter to the string in the following line: outfile.write("%s\n" % m.string[m.start():m.end()]) And you need to use m.search, not m.match in the line where you're actually apply the expression to the string m = patt.search(line) --Michael On 12/21/07, Que Prime <[EMAI

Re: [Tutor] Regular Expression

2007-12-21 Thread Tiger12506
>I need to pull the highligted data from a similar file and can't seem to >get > my script to work: > > Script: > import re > infile = open("filter.txt","r") > outfile = open("out.txt","w") > patt = re.compile(r"~02([\d{10}])") You have to allow for the characters at the beginning and end too. Tr

[Tutor] Regular Expression

2007-12-21 Thread Michael H. Goldwasser
Que, I haven't tested the script, but please note that patt.match(line) will only succeed when the pattern is at the start of the line. Use patt.search(line) if you want to find the pattern anywhere within the line. Based on your desired highlight, you might want to use the pattern, patt = re.c

[Tutor] Regular Expression

2007-12-21 Thread Que Prime
I need to pull the highligted data from a similar file and can't seem to get my script to work: Script: import re infile = open("filter.txt","r") outfile = open("out.txt","w") patt = re.compile(r"~02([\d{10}])") for line in infile: m = patt.match(line) if m: outfile.write("%s\n") infile.cl

Re: [Tutor] Regular Expression help - parsing AppleScript Lists as Strings

2007-11-01 Thread Andrew Wu
Ah - thanks for the correction! I missed the extra grouping and the extra spacing ... doh! Sorry about the HTML-formatted e-mail ... Thanks also for the pyparsing variant as well - I didn't know the module existed before! Andrew On 11/1/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > Andrew Wu

Re: [Tutor] Regular Expression help - parsing AppleScript Lists as Strings

2007-11-01 Thread Kent Johnson
Kent Johnson wrote: > You might want to look at doing this with pyparsing, I think it will > make it easier to get the data out vs just recognizing the correct pattern. Here is a pyparsing version that correctly recognizes all of your patterns and returns a (possibly nested) Python list in case

Re: [Tutor] Regular Expression help - parsing AppleScript Lists as Strings

2007-11-01 Thread Kent Johnson
Andrew Wu wrote: >pattern3 = ''' > ^{ > ( > %s > | {%s} # Possible to have 1 level of nested lists > ,?)* # Items are comma-delimited, except for the last item > }$ >''' % (pattern2, pattern2) The above doesn't allow comma after the first instance

[Tutor] Regular Expression help - parsing AppleScript Lists as Strings

2007-10-31 Thread Andrew Wu
Hi, I'm writing utilities to handle return values from AppleScript in python and one of the steps is recognizing when a returned value from an AppleScript execution (via popen and osascript) represents a list (in AppleScript) or not. For the most part I think I have the correct matching pattern,

Re: [Tutor] Regular Expression help

2007-06-29 Thread Gardner, Dean
] Sent: 27 June 2007 14:55 To: tutor@python.org; Gardner, Dean Subject: Re: [Tutor] Regular Expression help Gardner, Dean wrote: > Hi > > I have a text file that I would like to split up so that I can use it > in Excel to filter a certain field. However as it is a flat text file > I

Re: [Tutor] Regular Expression help

2007-06-27 Thread Kent Johnson
Gardner, Dean wrote: > Hi > > I have a text file that I would like to split up so that I can use it in > Excel to filter a certain field. However as it is a flat text file I > need to do some processing on it so that Excel can correctly import it. > > File Example: > tag desc

Re: [Tutor] Regular Expression help

2007-06-27 Thread Kent Johnson
Yikes! Sorry about all the duplicate postings. Thunderbird was telling me the send failed so I kept retrying; I guess it was actually sending! Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Regular Expression help

2007-06-27 Thread Kent Johnson
Gardner, Dean wrote: > Hi > > I have a text file that I would like to split up so that I can use it in > Excel to filter a certain field. However as it is a flat text file I > need to do some processing on it so that Excel can correctly import it. > > File Example: > tag desc

Re: [Tutor] Regular Expression help

2007-06-27 Thread Kent Johnson
Gardner, Dean wrote: > Hi > > I have a text file that I would like to split up so that I can use it in > Excel to filter a certain field. However as it is a flat text file I > need to do some processing on it so that Excel can correctly import it. > > File Example: > tag desc

Re: [Tutor] Regular Expression help

2007-06-27 Thread Kent Johnson
Gardner, Dean wrote: > Hi > > I have a text file that I would like to split up so that I can use it in > Excel to filter a certain field. However as it is a flat text file I > need to do some processing on it so that Excel can correctly import it. > > File Example: > tag desc

Re: [Tutor] Regular Expression help

2007-06-27 Thread Kent Johnson
Tom Tucker wrote: > #matchstr regex flow > # (\(\d+,\d+\)) # (0018,0014) > # \s # [space] > # (..*)# Contrast/Bolus Administration Route Sequence > # \s # space > # ([a-z]{2}) # SQ - two letters and no more > # \s # [s

Re: [Tutor] Regular Expression help

2007-06-27 Thread Reed O'Brien
On Jun 27, 2007, at 10:24 AM, Mike Hansen wrote: > > >> -Original Message- >> From: [EMAIL PROTECTED] >> [mailto:[EMAIL PROTECTED] On Behalf Of Gardner, Dean >> Sent: Wednesday, June 27, 2007 3:59 AM >> To: tutor@python.org >> Subject: [Tutor

Re: [Tutor] Regular Expression help

2007-06-27 Thread Mike Hansen
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Gardner, Dean > Sent: Wednesday, June 27, 2007 3:59 AM > To: tutor@python.org > Subject: [Tutor] Regular Expression help > > Hi > > I have a text file that I wo

Re: [Tutor] Regular Expression help

2007-06-27 Thread Mike Hansen
Argh... My e-mail program really messed up the threads. I didn't notice that there was already multiple replies to this message. Doh! Mike ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Regular Expression help

2007-06-27 Thread Kent Johnson
Gardner, Dean wrote: > Hi > > I have a text file that I would like to split up so that I can use it in > Excel to filter a certain field. However as it is a flat text file I > need to do some processing on it so that Excel can correctly import it. > > File Example: > tag desc

Re: [Tutor] Regular Expression help

2007-06-27 Thread Kent Johnson
Gardner, Dean wrote: > Hi > > I have a text file that I would like to split up so that I can use it in > Excel to filter a certain field. However as it is a flat text file I > need to do some processing on it so that Excel can correctly import it. > > File Example: > tag desc

Re: [Tutor] Regular Expression help

2007-06-27 Thread Tom Tucker
I think I have a solution. File (0012,0042) Clinical Trial Subject Reading ID LO 1 (0012,0050) Clinical Trial Time Point ID LO 1 (0012,0051) Clinical Trial Time Point Description ST 1 (0012,0060) Clinical Trial Coordinating Center Name LO 1 (0018,0010) Contrast/Bolus

[Tutor] Regular Expression help

2007-06-27 Thread Gardner, Dean
Hi I have a text file that I would like to split up so that I can use it in Excel to filter a certain field. However as it is a flat text file I need to do some processing on it so that Excel can correctly import it. File Example: tag descVR VM (0012,0042) Cl

Re: [Tutor] Regular expression questions

2007-05-03 Thread Bernard Lebel
Thanks a lot Kent, that indeed solves the issues altogether. Cheers Bernard On 5/3/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > Bernard Lebel wrote: > > Hello, > > > > Once again struggling with regular expressions. > > > > I have a string that look like "something_shp1". > > I want to repla

Re: [Tutor] Regular expression questions

2007-05-03 Thread Kent Johnson
Bernard Lebel wrote: > Hello, > > Once again struggling with regular expressions. > > I have a string that look like "something_shp1". > I want to replace "_shp1" by "_shp". I'm never sure if it's going to > be 1, if there's going to be a number after "_shp". > > So I'm trying to use regular exp

[Tutor] Regular expression questions

2007-05-03 Thread Bernard Lebel
Hello, Once again struggling with regular expressions. I have a string that look like "something_shp1". I want to replace "_shp1" by "_shp". I'm never sure if it's going to be 1, if there's going to be a number after "_shp". So I'm trying to use regular expression to perform this replacement. Bu

Re: [Tutor] regular expression

2006-08-03 Thread arbaro arbaro
Hello, Im just answering my own email, since I just found out what my error was. >From a regular expression howto: >http://www.amk.ca/python/howto/regex/regex.html The match() function only checks if the RE matches at the beginning of the string while search() will scan forward through the stri

Re: [Tutor] regular expression

2006-08-03 Thread Kent Johnson
arbaro arbaro wrote: > Hello, > > I'm trying to mount an usb device from python under linux. > To do so, I read the kernel log /proc/kmsg and watch for something like: > "<6> /dev/scsi/host3/bus0/target0/lun0/:<7>usb-storage: device scan > complete" > > When I compile a regular expression like:

[Tutor] regular expression

2006-08-03 Thread arbaro arbaro
Hello,I'm trying to mount an usb device from python under linux.To do so, I read the kernel log /proc/kmsg and watch for something like:  "<6> /dev/scsi/host3/bus0/target0/lun0/:<7>usb-storage: device scan complete" When I compile a regular _expression_ like:  "r = re.compile('<\d+>\s/dev/scsi/host

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Kent Johnson
Steve Nelson wrote: > Incidentally continuing my reading of the HOWTO I have sat and puzzled > for about 30 mins on the difference the MULTILINE flag makes. I can't > quite see the difference. I *think* it is as follows: > > Under normal circumstances, ^ matches the start of a line, only. On a >

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Steve Nelson
On 7/14/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > But for this particular application you might as well use > line.startswith('b') instead of a regex. Ah yes, that makes sense. Incidentally continuing my reading of the HOWTO I have sat and puzzled for about 30 mins on the difference the MULT

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Kent Johnson
Steve Nelson wrote: > On 7/14/06, John Fouhy <[EMAIL PROTECTED]> wrote: > > > m = re.match(...) > dir(m) > >> It will tell you what attributes the match object has. >> > > Useful - thank you. > > I am now confuse on this: > > I have a file full of lines beginning with

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Luke Paireepinart
> I have a file full of lines beginning with the letter "b". I want a > RE that will return the whole line if it begins with b. > > I find if I do eg: > > m = re.search("^b", "b spam spam spam") m.group() > 'b' > > How do I get it to return the whole line if it begins w

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Steve Nelson
On 7/14/06, John Fouhy <[EMAIL PROTECTED]> wrote: > >>> m = re.match(...) > >>> dir(m) > > It will tell you what attributes the match object has. Useful - thank you. I am now confuse on this: I have a file full of lines beginning with the letter "b". I want a RE that will return the whole line

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread John Fouhy
On 14/07/06, Steve Nelson <[EMAIL PROTECTED]> wrote: > How does one query a match object in this way? I am learning by > fiddling interactively. If you're fiddling interactively, try the dir() command -- ie: >>> m = re.match(...) >>> dir(m) It will tell you what attributes the match object has

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Kent Johnson
Steve Nelson wrote: > On 7/14/06, John Fouhy <[EMAIL PROTECTED]> wrote: > > >> It doesn't have to match the _whole_ string. >> > > Ah right - yes, so it doesn't say that it has to end with a b - as per > your comment about ending with $. > The matched portion must end with b, but it does

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Steve Nelson
On 7/14/06, John Fouhy <[EMAIL PROTECTED]> wrote: > It doesn't have to match the _whole_ string. Ah right - yes, so it doesn't say that it has to end with a b - as per your comment about ending with $. > If you look at the match object returned, you should se that the match > starts at position

Re: [Tutor] Regular Expression Misunderstanding

2006-07-14 Thread John Fouhy
On 14/07/06, Steve Nelson <[EMAIL PROTECTED]> wrote: > What I don't understand is how in the end the RE *does* actually match > - which may indicate a serious misunderstanding on my part. > > >>> re.match("a[bcd]*b", "abcbd") > <_sre.SRE_Match object at 0x186b7b10> > > I don't see how abcbd matches

[Tutor] Regular Expression Misunderstanding

2006-07-14 Thread Steve Nelson
Hello, I am reading the "Regular Expression HOWTO" at http://www.amk.ca/python/howto/regex/ I am at the bit where "greediness" is discussed with respect to metacharacters enabling repetition of sections of a RE. I understand the concept. The author gives a step by step example of how the matchi

Re: [Tutor] regular expression matching a dot?

2005-10-21 Thread Christian Meesters
Hi Frank & Kent & Hugo, Didn't have the time to read the list yesterday ... Thanks for pointing me to the regex-debuggers. Though I don't considered myself a regex-beginner I had to learn, that now that I'm using regexes only occasionally I might need some help here and there. Cheers, Christia

Re: [Tutor] regular expression matching a dot?

2005-10-20 Thread Hugo González Monteverde
I personally fancy Kiki, that comes with the WxPython installer... It has very nice coloring for grouping in Regexes. Hugo Kent Johnson wrote: > Frank Bloeink wrote: > >>There are some nice regex-debuggers out there that can help clearify >>what went wrong when a regex doesn't match when it sho

  1   2   >