1

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

Community
  • 1
  • 1
John
  • 529
  • 8
  • 20

1 Answers1

1

You can do:

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

Demo

dawg
  • 98,345
  • 23
  • 131
  • 206
  • Thank you so much. It works like a peach. I would have otherwise need to sift through 1200 lines and make changes to 360 of them. Much obliged... – John Mar 05 '16 at 17:17
  • Note that this is only as good as the problem definition in your example. The character class in group 1 will only capture spaces `[\r\n\t\f ]` and `[a-zA-Z0-9_]` You may have lines that have scented letters (`è` for example, symbols, etc, etc). You may want to use `ABCD[\w ]+` so that `\n` is not included. – dawg Mar 05 '16 at 17:21