问题
I try to use a lookbehind assertion in the atom editor. My text is the following:
<stop color="rgb(0,0,153)" value = "0.13"/>
<stop color="rgb(0,0,180)" value = "0.17"/>
<stop color="rgb(0,0,223)" value = "0.25"/>
I can do a lookahead assertion with .*(?=color\=)
. It selects everything before "color=". But if I try the lookbehind assertion .*(?<=color\=)
atom tells me "Invalid regular expression". It seems that atom does not recognize <
or >
as special character, because it shows it the same color as common letters and numbers. I also can't use the once-only subexpression ?>
.
Since I don't really find a hint which flavor of regex is used in atom I don't know which regex I should use instead. Apparently one without >
in it...
I know that this is xml and that I could extract the values with xml methods, but this is not part of what I want to achieve here.
回答1:
This thread in the atom discussion forum shows, that information about the regex dialect is indeed still missing in the official documentation. But they write in the discussion that Atom uses Javascript regex. And Javascript regex has no lookbehind implemented, while in contrast lookahead is implemented.
Hence you have to use a solution without lookbehind.
来源:https://stackoverflow.com/questions/37171447/lookbehind-assertion-regex-in-atom-editor