Re: [Tutor] regular expressions - backslashes

2006-04-06 Thread Kent Johnson
Justin Ezequiel wrote: > will try to convince my colleague to use string formatting > if he insists on regexp then he can do > re.sub(r'(?i)', apppath.replace('\\', ''), template) > > re.escape does not quite work for my example > re.sub(r'(?i)', re.escape(apppath), template) > 'C\\:\\n

Re: [Tutor] regular expressions - backslashes

2006-04-06 Thread Justin Ezequiel
Kent wrote: """The problem is that the re engine itself is interpreting the backslashes in the replacement pattern. With a single slash you get a newline even though the slash is a literal in the replacement string: So if you want a literal \ in your replacement text you have to escape the \, ev

Re: [Tutor] regular expressions - backslashes

2006-04-06 Thread Kent Johnson
Justin Ezequiel wrote: > a colleague demonstrated a problem he had with regular expressions > apppath = os.path.abspath(os.curdir) apppath > 'C:\\napp_and_author_query\\napp_and_author_query\\a b c d' template = r'\files' template > '\\files' re.sub(r'(?i)', apppath, templ

[Tutor] regular expressions - backslashes

2006-04-05 Thread Justin Ezequiel
a colleague demonstrated a problem he had with regular expressions >>> apppath = os.path.abspath(os.curdir) >>> apppath 'C:\\napp_and_author_query\\napp_and_author_query\\a b c d' >>> template = r'\files' >>> template '\\files' >>> re.sub(r'(?i)', apppath, template) 'C:\napp_and_author_query\napp_