[Tutor] regular expressions
alan.gauld at blueyonder.co.uk
Fri Jun 25 02:43:00 EDT 2004
> First is why does it ignore the P from the patterns?
P* means *zero* or more repetitions of P
For one or more repetitions you need to use P+
> Second I understand that search scans through the string looking for
> match. What I am wanting to do is use the \A switch , I think, that
> match only the start of the string.
Or use the re.match() function instead. Ironically the usual mistake
is to use match() when search() was neeeded, in your case its the
Still another way would be to change the pattern to use the ^ symbol
to indicate the beginning of the string.
The fun(?!) thing about regex is that there are usually multiple ways
of achieving the same end - all with very subtle gotchas attached...
More information about the Tutor