[Tutor] re.compile ??

lonetwin lonetwin@yahoo.com
Wed Apr 23 13:20:03 2003


Hi Anish,

On Wednesday 23 April 2003 08:57 pm, Mehta, Anish wrote:
> I am not getting what should  be the outcome of this line
> numberAddedRE = re.compile("(.*)#\d+$")

Re: One of the ways I try to decipher re's is by starting from the innermost 
re and reading upto the enclosing quotes. It has also helped me a lot when I 
"spell out" the re. That means when I see a  '.*' I say 'any character 
repeated 0 or more times'.

Now to your re ....lets see, the innermost is 
(.*) ---> any character repeated 0 or more times.
#    ---> followed by a '#'
\d+ ---> followed by *at least one* (that's what the '+' says) digit
$    ---> at the end of the line

so the above re will match 

"dsfsd#34213"
"     #33"
"__@#1111111"

but will not match (among various other combinations)
"# " ---> there should be at least one digit between '#' and the
          end of the line
"DF23#453   " ---> the digits should occur at the end of the line

HTH

Peace
Steve
-- 
Heisengberg might have been here.