[Tutor] re question

Kristoffer Erlandsson krier115@student.liu.se
Sat Apr 26 16:37:02 2003


On Sat, Apr 26, 2003 at 03:50:41PM -0400, Timothy M. Brauch wrote:
> I'm working with the re module, doing some file processing.  I have a
> question that maybe someone can explain to me.  The re module talks about
> raw strings and I'm not quite sure I understand what a raw string is and how
> it differs from a regular string.  What is the difference?

A raw string doesn't translate escape sequences and such. Raw strings are
preceeded by an 'r'. Example:

>>> print 'Hello\n'
Hello

>>> print r'Hello\n'
Hello\n
>>> 'Hello\n'
'Hello\n'
>>> r'Hello\n'
'Hello\\n'

In a raw string you can put special characters and likewise how you want
without them getting their special meaning, they are just characters. Or you
can see it so that Python automatically escapes the special characters so they
lose their special meaning.

Regards,
Kristoffer

-- 
Kristoffer Erlandsson
E-mail:  krier115@student.liu.se
ICQ#:    378225