Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

regex - replace characters in notepad++ BUT exclude characters inside single quotation marks(2nd)

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)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 [ f]
  • w is a short for word character [A-Za-z0-9_]

And replace with L1 to lower words captured inside the first capture group or U1 to upper.
Works for me in NP++ 6.7.9.2 with your sample data. See regex101 for testing the pattern.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...