i\'ve crafted this regular expression:
\\\\n<(\\w+)>(.+?)\\w+>\\\\n
to parse the foll
Before the regex compiler sees a string, Python has already processed the slash-escapes, therefore you'd have to escape it twice (e.g. \\\\n
for \\n
). However, Python has a handy notation for exactly this sort of thing, just stick an r
before the string:
regex = re.compile(r"""\\n<(\w+)>(.+?)\w+>\\n """)
By the way, I agree with the others here, do not use regexes to parse XML. However, hopefully you will find this string notation helpful in future regular expressions.