开发者

Eclipse find and replace with regex is not working with "(?=regex)"?

开发者 https://www.devze.com 2023-04-01 23:09 出处:网络
I tried to find and replace some tags with SpringSource Tool Suite(Eclipse). I want to change <annotation-driven /> to <mvc:annotation-driven /> but I don\'t want <beans:bean ..> to

I tried to find and replace some tags with SpringSource Tool Suite(Eclipse). I want to change <annotation-driven /> to <mvc:annotation-driven /> but I don't want <beans:bean ..> to be <mvc:beans:bean ...>.

So I made regex like this(actually the regex is longer than this but I made it simple):

Find: <(?=[^b])

Replace With: <mvc:

I added (?=regex) expression to avoid first character to be selected. It finds successfully but doesn't replace anything. If I remove the (?=regex) expression, it works fine but the first character is removed.

I开发者_StackOverflows it a bug? Or Did I do something wrong?


I would have used (?!b), but (?=[^b]) should work too. Anyway, try this:

Find: <([^b])

Replace: <mvc:$1

$1 should insert the contents of the first capturing group, i.e., the letter that isn't b.

If it doesn't work with $1, try <mvc:\1 instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消