[Tutor] redemo.py and r'python\.org'
Kent Johnson
kent37 at tds.net
Thu Oct 13 23:36:54 CEST 2005
Dick Moores wrote:
> I've begun to try out redemo.py to test and learn regular expressions. It
> doesn't seem to accept Python's raw strings as raw strings, e.g.,
> r'python\.org' for matching python.org and nothing else. Am I correct,
> or is there something I don't understand here?
In redemo you just type the actual regex string, no quotes or r prefix. So if you type into the top text box
python\.org
and in the middle text box
python.org
then you will get a match.
In your program then you have to type the regex as a string literal so you would type
r'python\.org'
>
> BTW redemo.py can be found in Python 2.4 in Tools\Scripts.
>
> BTW2 The new book, _Beginning Python: From Novice to Professional_, by
> Magnus Lie Hetland, has 16 pages on the re module, pp. 235-251.
>
> (A question about quoting in a Tutor post: in my 1st paragraph above, how
> could I have indicated that I am quoting both
>
> r'python\.org' and python.org
>
> without using quotation marks to do so, so as to not confuse the regex? I
> think I remember someone recently using angled brackets. So how about
> <r'python\.org'> and <python.org>? Is there a convention about this?)
I found it clear the way you typed it. In my response I set the strings off with newlines and an indent. Angle brackets would probably work fine too. IOW I don't think there is really a convention.
Kent
>
>
> Thanks,
>
> Dick Moores
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
More information about the Tutor
mailing list