Consider the following text file;
NETHERLANDS (THE)
BOLIVIA (PLURINATIONAL STATE OF)
COCOS (KEELING) ISLANDS (THE)
ANTIGUA AND BARBUDA
TEST1, SOME TEXT
TEST2, SAINT HELENA AND ASCENSION AND TRISTAN DA CUNHA
TEST3, BONAIRE AND SINT EUSTATIUS AND SABA
I'm trying to capture all characters after the first ,
and optionally separated by AND
, the desired result is:
No Match (no ,)
No Match (no ,)
No Match (no ,)
No Match (no ,)
SOME TEXT
SAINT HELENA - ASCENSION - TRISTAN DA CUNHA
BONAIRE - SINT EUSTATIUS - SABA
Using this post as an example, I've created the following regex:
/(?<= AND |\, )(.*)(?= AND |$)/mU
This works fine, as you can see here, except for the one case that does not contain a ,
(ANTIGUA AND BARBUDA
)
Question: How can I change this regex so that it will only match lines that contains at leat one
,
?
I've searched online for a solution, like this or this answer, unfortunately I was not able to add those fixes without breaking the positive lookbehind.