I have the following pattern:
(name|id)\s*=\s*('|")([a-zA-Z\-\_])+('|")
And I have to get all attributes name="a" or id="ab_c" which does not have the structure name="a-element" or id="a-element" (finishes with -element), I tried with:
(name|id)\s*=\s*('|")([a-zA-Z\_][^-element])+('|")
but it does not work, what is the mistake??
You want negative look-arounds, like this:
(name|id)\s*=\s*('|")([a-zA-Z\-_](?!-element))+('|")
(But keep in mind that you probably shouldn't be parsing XML manually.)
精彩评论