Reputation: 3113
I can't figure out how to use group matches for replacement.
Here is my issue: I have an sql file I want to modify in order to make it mysql compatible.
The file looks something like this:
INSERT INTO Client ([name], [id], [company]) VALUES ('Roger', 1, '[Coca-cola]');
INSERT INTO Client ([name], [id], [company]) VALUES ('Lisa', 2, '[Nike]');
I want it to look like this:
INSERT INTO Client (name, id, company) VALUES ('Roger', 1, '[Coca-cola]');
INSERT INTO Client (name, id, company) VALUES ('Lisa', 2, '[Nike]');
I managed to write this regex:
\\((\\[([^\\]]*)\\],? ?)+\\) VALUES
I am using sublimetext3. It is using the boost regex library.
But I don't know what to write for the replacement string.
Any ideas?
PS: The original file has several different tables with different number of rows and has 13000 lines.
Upvotes: 0
Views: 541
Reputation: 174706
Regex:
(?<=\(|, )\[|\](?=,|\))
Replace the matched brackets with an empty string.
Upvotes: 2
Reputation: 49097
I suggest to use the search string (?<!')\[|\](?!')
and an empty string as replace string.
Explanation:
(?<!')
... a negative lookbehind for character '
.
\[
... literal character [
.
|
... OR expression.
\]
... literal character ]
.
(?!')
... a negative lookahead expression for character '
.
Find an opening square bracket not preceded by a single quote OR a closing square bracket with next character not being a single quote.
Upvotes: 2