2008/11/21 harijay <[EMAIL PROTECTED]>:
> Hi
> I am a few months new into python. I have used regexps before in perl
> and java but am a little confused with this problem.
>
> I want to parse a number of strings and extract only those that
> contain a 4 digit number anywhere inside a string
>
> However the regexp
> p = re.compile(r'\d{4}')
>
> Matches even sentences that have longer than 4 numbers inside
> strings ..for example it matches "I have 3324234 and more"

Try with this:

p = re.compile(r'\d{4}$')

The $ character  matches the end of the string. It should work.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to