Search and Replace in textpad/notepadd++ using Reg

2019-08-09 19:45发布

问题:

I need to do search and replace in textpad or notepad++. So I am trying to use Regular Expressions. I have some lines like below

(C_ABCD_ehfjdhf dj hfdjhfhj and
(S_dfdfdddff 20 and
(P_ABCD_fmngfngm gfnm and

I need to check for the key word ABCD and if found , add a constant value before the last word. In result I want above lines to be as follows

(C_ABCD_ehfjdhf dj hfdjhfhj CONSTANT and
(S_dfdfdddff 20 and
(P_ABCD_fmngfngm gfnm CONSTANT and

Since first and third line had the keyword ABCD, the term CONSTANT needs to be added before ending word

I had raised a similar question before but I think I was not able to explain the problem correctly. Here is the link for that

Regular expressions to replace

回答1:

You can do:

(ABCD[\w\s]+)( [a-zA-Z]+)$

Demo