Mansoor Akram
Mansoor Akram

Reputation: 2056

Selecting second occurence of word using regex

I have this string output:

"Appliances Air Conditioners
Appliances Split AC"

I am trying to use regex to remove the second occurrence of "Appliances" word:

(Appliances.\*?(Appliances))*

But getting no success.

Upvotes: 0

Views: 70

Answers (1)

anubhava
anubhava

Reputation: 785156

You can search for:

\b(Appliances\b[\s\S]*?)\bAppliances\s+

And replace by \1

RegEx Demo

You need to use DOTALL or [\s\S] to match a newline.

Upvotes: 3

Related Questions