There's a string that goes like this:
|Africa||Africans||African Society||Go Africa Go||Mafricano||Go Mafricano Go||West Africa|
.
I'm attempting to craft a regular expression that will only match terms containing the word Africa
or any variation of it (yes to all terms above except for |Mafricano|
and |Go Mafricano Go|
). Each term is enclosed between two |
.
Currently, I've devised: /\|[^\|]*africa[^\|]*\|/gi
, which is written as follows:
\|
Match|
[^\|]*
Match zero to unlimited instances of any character except|
africa
Matchafrica
literally
[^\|]*
Match zero to unlimited instances of any character except|
\|
Match|
I tried adding in ((?:\s)|(?!\w))
to make it
/\|[^\|]*((?:\s)|(?!\w))africa[^\|]*\|/gi
. While it successfully excludes |Mafricano|
and |Go Mafricano Go|
, it also leaves out all other entries except for |West Africa|
and |Go Africa Go|
. This is a step in the right direction but I need it to include all single words with Africa
and its derivatives too.
Any assistance would be appreciated?