python - Error says Unexpected Character, while back referencing in conditional regular expression -
purpose match pattern "abc"
or "<abc>"
not "<abc"
or "abc>"
. closing angle braces @ end should matched if opening angle braces exist. logic thought work following
(<)?(abc)(?(\1))>
i'm trying use referencing , conditionals available. error says unexpected character @ second question mark "?"
in regular expression. incase needed i'm trying on python.
the syntax conditionals different, try this:
(<)?(abc)(?(1)>|)
this means:
if (1)
(if group 1 matched), match >
, otherwise (|
), match nothing. if want prevent match of abc>
, need negative lookahead:
(<)?(abc)(?(1)>|(?!>))
but considered more complex simpler <abc>|(?<!<)abc(?!>)
regex posted donal.
Comments
Post a Comment