3

I'm using regular expression in Notepad++, trying to delete everything after a particular word.

For example here is my text:

Bull01 blah blah
Bull02 Blah blah
Bull03 Blah
Bull04 Blah
Bull05 Blah
**
Bull300 Blah blah blah

etc..

Im trying to delete everything after the word Bull, so that my results ends up being just Bull. I thought it was as simple as searching for

Bull.*

but that deletes the whole row, including the word Bull.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
Daniel Ellison
  • 1,339
  • 4
  • 27
  • 49

3 Answers3

6

Use a look behind:

Search: (?<=Bull).*
Replace: <blank>

The handy thing about look arounds is that they assert a match without consuming anything, so you don't have to sully yourself with back references.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
2

You can search for (Bull).* and replace it with $1 - but take care to not set dot matches \r and \n

Sebastian Proske
  • 8,255
  • 2
  • 28
  • 37
0

You may use a match reset operator \K:

\K keeps the text matched so far out of the overall regex match. h\Kd matches only the second d in adhd.

So, you match whatever you like (even quantified patterns like \d+ or [a-z]{7,}), then insert \K and add .+ to grab the rest of the line (1 or more characters other than line break chars):

Bull\K.+

Then all what remains is to use an empty string in the replacement pattern.

See the Notepad++ screenshot:

enter image description here

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563