问题
replace characters in notepad++ BUT exclude characters inside single quotation marks
Sorry to all users (especially to Avinash Raj) who answered already 1st similiar question - I did simply forget the 2nd kind of string. (And (that is the sad thing) - I'm not able to adjust the solution from 1st similiar question to the 2nd kind of string...)
I have TWO different strings in this kind:
SELECT column_name FROM table_name WHERE column_name IN ('A' , 'st9u' ,'Meyer', ....);
WHERE a.object_type IN (' 'TABLE'', ''MATEerialIZED VIE3W' ')
I want replace all characters in notepad++ from upper to lower, BUT exclude from replacement characters inside single quotation marks.
condition: It exists no solid structure before/behind/between the single quotation marks part!
(That means - I can not use the keyword "IN" or signs like "," or "(" or ")" or ";" for this regex ...!)
The once thing is, that two structures for single quotation marks are possible: 'Word|Number' or ''Word|Number'' (but, as shown in 2nd example, with different number of spaces between every single quotation mark!).
target string (the characters inside single quotation marks have to stay unchangend):
select column_name from table_name where column_name in ('A' , 'st9u' ,'Meyer', ....);
where a.object_type in (' 'TABLE'', ''MATerialIZED VIE3W' ')
How can I exclude in notepad++ the single quotation marks part (from replacement)?
回答1:
Could combine a recursive part for getting '
... '
.... abc
''
and use \K for resetting after. This is the part that needs to be skipped. And using kind of the trick, matching remaining words in pipe:
'\s*(?0)?[^']*'\K|(\w+)
(?0)?
here the pattern is optionally pasted from start\s
is a shorthand for whitespace character[ \t\r\n\f]
\w
is a short for word character[A-Za-z0-9_]
And replace with \L\1
to lower words captured inside the first capture group or \U\1
to upper.
Works for me in NP++ 6.7.9.2 with your sample data. See regex101 for testing the pattern.
来源:https://stackoverflow.com/questions/32037307/replace-characters-in-notepad-but-exclude-characters-inside-single-quotation-m