user11484870
user11484870

Reputation: 21

RegEx for matching everything except a text between two words

I have a text:

"The quick brown fox jumps over the lazy dog"

and I need to match everything except the text between a word and the first occurrence of a letter after this word as follows (in this case between brown and the first occurrence of "l"):

"The quick brown lazy dog"

I have tried some possible solutions but the closest match I have in my hand is exactly the opposite:

(?<=brown ).*?(?=l)

which matches " fox jumps over the"

EDIT:

I am using Klipfolio tool and the exact text I have is like this:

["String1: value1","String2: value2","String3: value3"]

And I want to match all except value1 and replace it with empty string.

Function I am using is SUBSTITUTE_REGEX

Upvotes: 2

Views: 978

Answers (2)

user557597
user557597

Reputation:

As mentioned, the simplest way is to do a string replacement.

To do the inverse is more involved and is done like this:

Find (.*?brown ).*?(l.*)|(.+)
Replace $1$2$3

https://regex101.com/r/x8QW6r/1

Upvotes: 1

ruohola
ruohola

Reputation: 24137

You can just use your original pattern and replace the matched part with an empty string "".

Alternative way to do this is to create two match groups, which you can then combine to get the wanted result:

(.*brown )(?:[^l]*)(.*)
Full match  0-43   The quick brown fox jumps over the lazy dog
Group 1.    0-16   The quick brown 
Group 2.    35-43  lazy dog

Demo

Upvotes: 0

Related Questions