Rawrshark
Rawrshark

Reputation: 109

RegEx - How to delete everything before the third empty space in a Notepad++ line?

I'm having trouble figuring out the correct regular expression formula to delete all characters before the third empty space in a Notepad++ line. I have text that reads this:

kea k3fi ifea1k monkey
k22a kfea.f fkaa99 parrot
23 ma feaj bear

I want the text to be manipulated so it reads this:

monkey
parrot
bear

Does anyone have an idea? Any help would be much appreciated. Thank you!

Edit >> Problem solved. Thank you all for your help! I wish I was as smart as you guys, haha. Cheers!

Upvotes: 4

Views: 6035

Answers (5)

Toto
Toto

Reputation: 91385

If you want to deal also with tabulations or other space characters

find:    ^(\S+\s+){3}
replace: "nothing"

\s stands any space character
\S stands for non space character

Upvotes: 0

0x90
0x90

Reputation: 40982

Your regex is:

^([^ ]+ ){3}

start with 3 none spaced words three times.

Upvotes: 1

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89557

You can do this:

find: ^([^ ]+ ){3}(.+)$
replace: $2

and push replaceAll!

Upvotes: 0

perreal
perreal

Reputation: 97938

Another way is to replace:

^([^ ]* ){3} 

or:

^[^ ]* [^ ]* [^ ]*  

with the empty string

Upvotes: 1

acdcjunior
acdcjunior

Reputation: 135762

Use:

^(.*? ){3}

And leave "Replace with:" with nothing. This will turn:

kea k3fi ifea1k monkey
k22a kfea.f fkaa99 parrot
23 ma feaj bear

Into:

monkey
parrot
bear



On the other hand, if your file is like:

kea k3fi ifea1k monkey monkey monkey monkey monkey
k22a kfea.f fkaa99 parrot parrot parrot parrot parrot
23 ma feaj bear bear bear bear bear

The regex above is too simple. You'll have to use the regex:

^((.*? ){3})(.*?)$

And leave "Replace with:" with $3.

This will turn the file above into:

monkey monkey monkey monkey monkey
parrot parrot parrot parrot parrot
bear bear bear bear bear

Upvotes: 9

Related Questions