Reputation: 41381
I need to replace the following:
CREATE TABLE /*!32312 IF NOT EXISTS*/ `access`
to
CREATE TABLE IF NOT EXISTS `access`
I've tried
:%s/\/\*\!\d+(.*)\*\//\1/g
But that didn't seem to go. What am I doing wrong?
Upvotes: 0
Views: 381
Reputation: 7505
Slightly different and more efficient with [^*]+ :-)
1,$s/\v\/\*\!\d+\s*([^*]+)\*\//\1
Upvotes: 1
Reputation: 231143
vim requires backslashing + (or use * instead). Also, you need to backslash grouping parenthesis in vim. Thus:
:%s/\/\*\!\d\+\(.*\)\*\//\1/g
Yes, vim's old-style posix regexes suck :/
Edit: As mentioned in the comments below, + does work if escaped as \+. And \d actually is supported, oops. Edited the example regex to correct for this. Also see Brian Carper's example for a more succinct and readable version.
Upvotes: 4
Reputation: 72926
Use "very magic", and use delimiters other than the default to make this easier to read (and remember).
:%s@\v/\*!\d+(.*)\*/@\1@g
Without "very magic" you have to put a backslash in front of +
and ()
(but not in front of *
or some other things). It's not very consistent.
Upvotes: 4