Gunjan Amit
Gunjan Amit

Reputation: 11

Regex to extract specific words

I am looking for regex to extract following words from text. For example, the word which comes after "Replaced" in each of these lines:

Replaced disk 

Replaced floppy

Replaced memory

Please suggest the regex for it.

Upvotes: 1

Views: 343

Answers (3)

Alan Moore
Alan Moore

Reputation: 75252

We can't really help you without more details (like which regex flavor you're using, for example), but you probably want to match it with something like this:

Replaced\s+(\w+)\b

...and then extract the desired portion from capturing group #1.

Upvotes: 1

Wouter J
Wouter J

Reputation: 41934

I think

/Replaced\s(\w*?)/

Or:

/(?<=Replaced\s)(\w*)/

If you only want to select the word and not Replaced.

Upvotes: 0

burning_LEGION
burning_LEGION

Reputation: 13460

use this regex (?<=Replaced\s*)(.+)

Upvotes: 0

Related Questions