strugglingoldie
strugglingoldie

Reputation: 13

Inverse of this regex expression

I have a list:

50 - David Herd (1961-1968)
49 - Teddy Sheringham (1997-2001)
48 - George Wall (1906-1915)
47 - Stan Pearson (1935-1954)
46 - Harry Gregg (1957-1966)
45 - Paddy Crerand (1963-1971)
44 - Jaap Stam (1998-2001)
43 - Paul Ince (1989-1995)
42 - Dwight Yorke (1998-2002)

I want to select all characters EXCEPT the first and last name with the space in between in order to delete them and leave just the first name, space and last name.

So far I can select the first name, space and last name with:

([[a-zA-Z]+\s[a-zA-Z]+)

But I am unsure of how to 'invert' this expression. Any pointers would be much appreciated.

Upvotes: 1

Views: 57

Answers (2)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522741

If regex replacement be an option for you, you could try the following in regex mode:

Find:    \d+ - (\w+(?: \w+)+) \(\d{4}-\d{4}\)
Replace: $1

Demo

Upvotes: 2

The fourth bird
The fourth bird

Reputation: 163632

One option is to match the surrounded data, and capture the firstname space lastname.

In the replacement use the capture group.

^.*?\b([a-zA-Z]+\s[a-zA-Z]+)\b.*

Regex demo

Upvotes: 1

Related Questions