Python's regular expression help

2010-04-29 Thread goldtech
Hi, Trying to start out with simple things but apparently there's some basics I need help with. This works OK: import re p = re.compile('(ab*)(sss)') m = p.match( 'absss' ) m.group(0) 'absss' m.group(1) 'ab' m.group(2) 'sss' ... But two questions: How can I operate a regex on a string

Re: Python's regular expression help

2010-04-29 Thread Dodo
Le 29/04/2010 20:00, goldtech a écrit : Hi, Trying to start out with simple things but apparently there's some basics I need help with. This works OK: import re p = re.compile('(ab*)(sss)') m = p.match( 'absss' ) m.group(0) 'absss' m.group(1) 'ab' m.group(2) 'sss' ... But two questions:

Re: Python's regular expression help

2010-04-29 Thread MRAB
goldtech wrote: Hi, Trying to start out with simple things but apparently there's some basics I need help with. This works OK: import re p = re.compile('(ab*)(sss)') m = p.match( 'absss' ) m.group(0) 'absss' m.group(1) 'ab' m.group(2) 'sss' ... But two questions: How can I operate a regex

Re: Python's regular expression help

2010-04-29 Thread Tim Chase
On 04/29/2010 01:00 PM, goldtech wrote: Trying to start out with simple things but apparently there's some basics I need help with. This works OK: import re p = re.compile('(ab*)(sss)') m = p.match( 'absss' ) f=r'abss' f 'abss' m = p.match( f ) m.group(0) Traceback (most recent call

Re: Python's regular expression help

2010-04-29 Thread goldtech
On Apr 29, 11:49 am, Tim Chase python.l...@tim.thechases.com wrote: On 04/29/2010 01:00 PM, goldtech wrote: Trying to start out with simple things but apparently there's some basics I need help with. This works OK: import re p = re.compile('(ab*)(sss)') m = p.match( 'absss' )

A bug in Python's regular expression engine?

2007-11-27 Thread Just Another Victim of the Ambient Morality
This won't compile for me: regex = re.compile('(.*\\).*') I get the error: sre_constants.error: unbalanced parenthesis I'm running Python 2.5 on WinXP. I've tried this expression with another RE engine in another language and it works just fine which leads me to believe the

Re: A bug in Python's regular expression engine?

2007-11-27 Thread Diez B. Roggisch
Just Another Victim of the Ambient Morality wrote: This won't compile for me: regex = re.compile('(.*\\).*') I get the error: sre_constants.error: unbalanced parenthesis I'm running Python 2.5 on WinXP. I've tried this expression with another RE engine in

Re: A bug in Python's regular expression engine?

2007-11-27 Thread Neil Cerutti
On 2007-11-27, Just Another Victim of the Ambient Morality [EMAIL PROTECTED] wrote: This won't compile for me: regex = re.compile('(.*\\).*') I get the error: sre_constants.error: unbalanced parenthesis Hint 1: Always assume that errors are in your own code. Blaming library

Re: A bug in Python's regular expression engine?

2007-11-27 Thread Paul Hankin
On Nov 27, 3:48 pm, Just Another Victim of the Ambient Morality [EMAIL PROTECTED] wrote: This won't compile for me: regex = re.compile('(.*\\).*') I get the error: sre_constants.error: unbalanced parenthesis I'm running Python 2.5 on WinXP. I've tried this expression with

Re: A bug in Python's regular expression engine?

2007-11-27 Thread Just Another Victim of the Ambient Morality
Paul Hankin [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Nov 27, 3:48 pm, Just Another Victim of the Ambient Morality [EMAIL PROTECTED] wrote: This won't compile for me: regex = re.compile('(.*\\).*') I get the error: sre_constants.error: unbalanced parenthesis

Re: A bug in Python's regular expression engine?

2007-11-27 Thread MonkeeSage
On Nov 27, 10:52 am, MonkeeSage [EMAIL PROTECTED] wrote: On Nov 27, 10:19 am, Just Another Victim of the Ambient Morality [EMAIL PROTECTED] wrote: That is funny. Thank you for your help... Just for clarification, what does the r in your code do? It means a raw string (as you know

Re: Python's regular expression?

2006-05-10 Thread Edward Elliott
bruno at modulix wrote: From a readability/maintenance POV, Perl is a perfect nightmare. It's certainly true that perl lacks the the eminently readable quality of python. But then so do C, C++, Java, and a lot of other languages. And I'll grant you that perl is more susceptible to the

Re: Python's regular expression?

2006-05-10 Thread Dave Hansen
On Wed, 10 May 2006 06:44:27 GMT in comp.lang.python, Edward Elliott [EMAIL PROTECTED] wrote: Would I recommend perl for readable, maintainable code? No, not when better options like Python are available. But it can be done with some effort. I'm reminded of a comment made a few years ago by

Re: Python's regular expression?

2006-05-10 Thread Dave Hughes
Dave Hansen wrote: On Wed, 10 May 2006 06:44:27 GMT in comp.lang.python, Edward Elliott [EMAIL PROTECTED] wrote: Would I recommend perl for readable, maintainable code? No, not when better options like Python are available. But it can be done with some effort. I'm reminded of

Re: Python's regular expression?

2006-05-09 Thread Mirco Wahab
Hi Duncan Nick Craig-Wood wrote: Which translates to match = re.search('(blue|white|red)', t) if match: else: if match: else: if match: This of course gives priority to colours and only looks for garments or footwear if the it hasn't matched on a prior

Re: Python's regular expression?

2006-05-09 Thread bruno at modulix
Davy wrote: Hi all, (snip) Does Python support robust regular expression like Perl? Yes. And Python and Perl's File content manipulation, which is better? From a raw perf and write-only POV, Perl clearly beats Python (regarding I/O, Perl is faster than C - or it least it was the last time

Re: Python's regular expression?

2006-05-09 Thread Duncan Booth
Mirco Wahab wrote: If you wouldn't need dictionary lookup and get away with associated categories, all you'd have to do would be this: $PATTERN = qr/ (blue |white |red)(?{'Colour'}) | (socks|tights)(?{'Garment'}) | (boot |shoe |trainer)(?{'Footwear'})

Python's regular expression?

2006-05-08 Thread Davy
Hi all, I am a C/C++/Perl user and want to switch to Python (I found Python is more similar to C). Does Python support robust regular expression like Perl? And Python and Perl's File content manipulation, which is better? Any suggestions will be appreciated! Best regards, Davy --

Re: Python's regular expression?

2006-05-08 Thread Lawrence Oluyede
Davy [EMAIL PROTECTED] writes: Does Python support robust regular expression like Perl? Yep, Python regular expression is robust. Have a look at the Regex Howto: http://www.amk.ca/python/howto/regex/ and the re module: http://docs.python.org/lib/module-re.html -- Lawrence -

Re: Python's regular expression?

2006-05-08 Thread Mirco Wahab
Hi Davy wrote: I am a C/C++/Perl user and want to switch to Python OK (I found Python is more similar to C). ;-) More similar than what? Does Python support robust regular expression like Perl? It supports them fairly good, but it's not 'integrated' - at least it feels not integrated for

Re: Python's regular expression?

2006-05-08 Thread Davy
Hi Mirco, Thank you! More similar than Perl ;-) And what's 'integrated' mean (must include some library)? I like C++ file I/O, is it 'low' or 'high'? Regards, Davy -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's regular expression?

2006-05-08 Thread Davy
By the way, is there any tutorial talk about how to use the Python Shell (IDE). I wish it simple like VC++ :) Regards, Davy -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's regular expression?

2006-05-08 Thread Mirco Wahab
Hi Davy More similar than Perl ;-) But C has { }'s everywhere, so has Perl ;-) And what's 'integrated' mean (must include some library)? Yes. In Python, regular expressions are just another function library - you use them like in Java or C. In Perl, it's part of the core language, you use

Re: Python's regular expression?

2006-05-08 Thread John Machin
On 8/05/2006 10:31 PM, Mirco Wahab wrote: [snip] Lets see - a really simple find/match would look like this in Python: import re t = 'blue socks and red shoes' p = re.compile('(blue|white|red)') if p.match(t): What do you expect when t == green socks and red shoes? Is it

Re: Python's regular expression?

2006-05-08 Thread Duncan Booth
Mirco Wahab wrote: Lets see - a really simple find/match would look like this in Python: import re t = 'blue socks and red shoes' p = re.compile('(blue|white|red)') if p.match(t): print t which prints the text 't' because of the positive pattern match. In

Re: Python's regular expression?

2006-05-08 Thread Mirco Wahab
Hi John import re t = 'blue socks and red shoes' p = re.compile('(blue|white|red)') if p.match(t): What do you expect when t == green socks and red shoes? Is it possible that you mean to use search() rather than match()? This is interesting. What's in this example the

Re: Python's regular expression?

2006-05-08 Thread Mirco Wahab
Hi Duncan There is no need to compile the regular expression in advance in Python either: ... The only advantage to compiling in advance is a small speed up, and most of the time that won't be significant. I read 'some' introductions into Python Regexes and got confused in the first

Re: Python's regular expression?

2006-05-08 Thread John Machin
On 8/05/2006 11:13 PM, Mirco Wahab wrote: Hi John import re t = 'blue socks and red shoes' p = re.compile('(blue|white|red)') if p.match(t): What do you expect when t == green socks and red shoes? Is it possible that you mean to use search() rather than match()? This is

Re: Python's regular expression?

2006-05-08 Thread Mirco Wahab
Hi John But what would be an appropriate use of search() vs. match()? When to use what? ReadTheFantasticManual :-) From the manual you mentioned, i don't get the point of 'match'. So why should you use an extra function entry match(), re.match('whatever', t): which is, according to

Re: Python's regular expression?

2006-05-08 Thread Nick Craig-Wood
Mirco Wahab [EMAIL PROTECTED] wrote: After some minutes in this NG I start to get the picture. So I narrowed the above regex-question down to a nice equivalence between Perl and Python: Python: import re t = 'blue socks and red shoes' if re.match('blue|white|red', t):

Re: Python's regular expression?

2006-05-08 Thread Duncan Booth
Nick Craig-Wood wrote: Which translates to match = re.search('(blue|white|red)', t) if match: print Colour:, match.group(1) else: match = re.search('(socks|tights)', t) if match: print Garment:, match.group(1) else: match =

ANN: pyregex 0.5 - command line tools for Python's regular expression

2006-03-09 Thread [EMAIL PROTECTED]
pyregex is a command line tools for constructing and testing Python's regular expression. Features includes text highlighting, detail break down of match groups, substitution and a syntax quick reference. It is released in the public domain. Screenshot and download from http://tungwaiyip.info