From: Kevin B. <kb...@ca...> - 2001-07-03 15:27:21
|
You're not quoting the backslashes. You can either double the backslashes: s = re.sub("^(\\s*)Title","\\1Dataset_Title",s) Or use raw strings (preferred): s = re.sub(r"^(\s*)Title",r"\1Dataset_Title",s) kb Chris Gokey wrote: > > Hi, > > I'm trying to use a regular expression that uses backreferences in python. > Can someone tell me where I cam going wrong? > > [cgokey@cgokey cgokey]$ jython > Jython 2.1a1 on java1.3.0 (JIT: jitc) > Type "copyright", "credits" or "license" for more information. > >>> import re > >>> s = " Title: Ice Core Records" > >>> s = re.sub("^(\s*)Title","\1Dataset_Title",s); > >>> s > '\001Dataset_Title: Ice Core Records' > >>> print s > Dataset_Title: Ice Core Records > >>> > > It looks like it isn't using the back reference? The resulting output > should be indented 3 spaces. > > Thanks, > Chris > > -- > __________________________________________________ > /\ \ > \_| Christopher D. Gokey, SSAI, NASA/GCMD | > | 18 Martin Road, Shelburne Falls, MA 01370 | > | Phone: Voice (413) 625-8129 / FAX 208-248-9055 | > | cg...@gc... / http://gcmd.nasa.gov | > | ICQ #52132386, AOL IM: chrisgokey | > | _____________________________________________|_ > \_/______________________________________________/ > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > http://lists.sourceforge.net/lists/listinfo/jython-users |