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?
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?
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.
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.
Slightly different and more efficient with [^*]+ :-)
1,$s/\v\/\*\!\d+\s*([^*]+)\*\//\1