Lookbehind assertion regex in atom editor

核能气质少年 提交于 2019-12-12 13:33:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!