2

I'm trying to edit some big file and i need to add some symbols at the end of each line containing string. Example:

subject aaa tested
subject bbb tested
subject ccc tested

If there's 'subject bbb' in line id like to add 'ok' at the end.

subject aaa tested
subject bbb tested ok
subject ccc tested

So far I'm using Notepad++ and I'm here:

FIND: ^.*(subject bbb).*$
REPLACE: \1 ok

Output:

subject bbb ok

Any tips?

zzzareck
  • 34
  • 1

2 Answers2

0

Change your regex to ^.*(subject bbb.*)$

nessuno
  • 23,549
  • 5
  • 71
  • 70
0

You need to match the whole line and then replace with $& ok:

^.*subject bbb.*$

No capturing group is necessary since you replace the whole match value ($& is a back-reference to the whole matched text).

Also, if you need to match bbb or subject as a whole word, you need to use word boundary \b:

^.*\bsubject bbb\b.*$

See screenshot:

enter image description here

Wiktor Stribiżew
  • 484,719
  • 26
  • 302
  • 397
  • Thank You a lot for great explanation stribizhev! Can You refer any good sites to learn some regex basics? – zzzareck Sep 28 '15 at 21:42
  • Regex basics are covered at [regular-expressions.info](http://regular-expressions.info) and to test your regexps, you can use [regex101.com](http://regex101.com). Also, check the [What does this regex mean?](http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) SO post. – Wiktor Stribiżew Sep 28 '15 at 22:17