开发者

Confusing regex behavior when combining ` with (

开发者 https://www.devze.com 2023-02-19 22:46 出处:网络
In order to work around a mysql 5.0 to 5.1 compatibility issue, I\'m trying to change this pattern: KEY `brand_id` (`brand_id`) USING开发者_Go百科 BTREE

In order to work around a mysql 5.0 to 5.1 compatibility issue, I'm trying to change this pattern:

KEY `brand_id` (`brand_id`) USING开发者_Go百科 BTREE

to this:

KEY `brand_id` USING BTREE (`brand_id`)

Running the following regex in vim locates all the occurrences of the issue:

KEY `.*` \(.*\) USING BTREE

So, I tried just modifying this to the following substitution string, but it can no longer locate the matching strings. Why?

%s/KEY (`.*`) (\(.*\)) USING BTREE/KEY \1 USING BTREE (\2)/gc


I don't know why, but in Vim you need to escape the matching parentheses and leave them alone when they are to be taken literally. Try:

%s/KEY \(`.*`\) \((.*)\) USING BTREE/KEY \1 USING BTREE \2/gc
0

精彩评论

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

关注公众号