It is not possible to redefine anchor behavior.
To match a //
with any number of characters other than CR and LF after it, use a negated character class [^
]
with *
quantifier:
L = re.findall(rb'//[^
]*', input)
Note that this approach does not require using re.M
and re.S
flags.
Or, you can add
?
before a $
and enclose this part in a positive look-ahead (also, you will beed a *?
lazy quantifier with .
):
rb'//.*?(?=
?$)'
The point in using a lookahead is that $
itself is a kind of a lookahead since it does not really consume the
character. Thus, we can safely put it into a look-ahead with optional
.
Maybe this is not that pertinent since it is from MSDN, but I think it is the same for Python:
Note that $
matches
but does not match
(the combination of carriage return and newline characters, or CR/LF
). To match the CR/LF
character combination, include
?$
in the regular expression pattern.
In PCRE, you can use (*ANYCRLF), (*CR) and (*ANY) to override the default behavior of the $ anchor, but not in Python.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…