I have a regular expression which works perfectly well (although I am sure it is weak) in .NET/C#:
((^|\s))(?<tag>\@(?<tagname>(\w|\+)+))(?($|\s|\.))
I am trying to move it over to Python, but I seem to be running into a formatting issue (invalid expression exception).
It is a lame question/request, but I have been staring at this for a while, but nothing obvious is jumping out at me.
Note: I am simply trying
r = re.compile('((^|\s))(?<tag>\@(?<tagname>(\w|\+)+))(?($|\s|\.))')
Thanks,
Scott
There are some syntax incompatibilities between .NET regexps and PCRE/Python regexps :
(?<name>...)is(?P<name>...)(?...)does not exist, and as I don’t know what it is used for in .NET I can’t guess any equivalent. A Google codesearch do not give me any pointer to what it could be used for.Besides, you should use Python raw strings (
r"I am a raw string") instead of normal strings when expressing regexps : raw strings do not interpret escape sequences (like\n). But it is not the problem in your example as you’re not using any known escape sequence which could be replaced (\sdoes not mean anything as an escape sequence, so it is not replaced).