DoogyHtw
DoogyHtw

Reputation: 341

RegEx : How to exclude a words from a match list

I'm new with regex and I'm having a trouble with excluding a word from a list

The RegEx :

(?<=[\s,*])[A-Za-z]\w*(?=[\s,*=;])

The Data :

keyword1 Apple
keyword2    Beer=0
keyword1     China,    Dime, Egg,    Fly, Google,   Koala, Lime

The result :

Apple
keyword2 
Beer
keyword1
China
Dime
Egg
Fly
Google
Koala
Lime

The Result I expected is simply Apple Beet China Dime Egg Fly Google Koala Lime

The idea is : If I found one keyword1 or keyword2 then collect the 'next' words if the 'next' word is divided with comma (,) then collect each word in the comma. but don't include the keywords in the result.

I've tried all day but at the end I realized I need help on this..

Regards,

Ferry

Upvotes: 2

Views: 782

Answers (1)

Core_F
Core_F

Reputation: 3442

If you want to exclude the "keyword" you can do it like this:

(?!keyword)(?<=[\s,*])[A-Za-z]\w*(?=[\s,*=;])

Result: Apple Beer China Dime Egg Fly Google Koala

Upvotes: 2

Related Questions