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
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:
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
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
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' )
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
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
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
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
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
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
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
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
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
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
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
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'})
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
--
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 -
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
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
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
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
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
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
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
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
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
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
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):
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 =
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
32 matches
Mail list logo