Christophe C.
Christophe C.

Reputation: 147

how to find comma matches containing a specific word?

In this string :

GPN1 VRT Full competence (Tel),GPN1 VRT midle (Tel) ,GPN1 Open Mobile AC GNE (Tel),GPN1 VRT Best competence (Tel)

I would like to extract all the content between commas containing the word VRT.

I tried this regular expression : [\s\w]*VRT.*?(?=,).

It works on the first one but I can't repeat it so that it gets me all the others.

Could you, please, help me?

Upvotes: 1

Views: 143

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626825

You can use

[^,]*VRT[^,]*

See the regex demo. If the VRT must be matched as a whole word, add word boundaries:

[^,]*\bVRT\b[^,]*

See this regex demo. Details:

  • [^,]* - zero or more non-commas
  • \bVRT\b - VRT enclosed with word boundaries
  • [^,]* - zero or more non-commas.

Upvotes: 1

Related Questions