regular expression
Sean 'Shaleh' Perry
shalehperry at attbi.com
Sat May 18 16:15:27 EDT 2002
On 18-May-2002 Batara Kesuma wrote:
> Hi Sean,
>
> On Sat, 18 May 2002 10:46:19 -0700 (PDT)
> "Sean 'Shaleh' Perry" <shalehperry at attbi.com> wrote:
>
>> you are very close to what you need.
>>
>> rule = re.compile(r'^\d{6}$') # ^ means start of string, then \d{6} is 6
>> numbers
>> # then $ is end of string.
>
> Thank you very much. But what does the 'r' in (r'^\d{6}$') means?
>
r'' is a 'raw' string, the contents of it generally do not need to be escaped.
If you did not use the r'' syntax the above call would have been:
rule = re.compile('^\\d{6}6') # note the escaped backslash.
If you have a more complex regex all of the escaping makes it hard to read.
rule = re.compile('^\\d{6}\\s+\\d{3}')
More information about the Python-list
mailing list