I've got the following string: |Africa||Africans||African Society||Go Africa Go||Mafricano||Go Mafricano Go||West Africa|.
I am trying to write a regular expression that only matches terms that include the word Africa or any deriative of it (meaning yes to all terms above except for |Mafricano| and |Go Mafricano Go|. Each term is enclosed between two |.
Right now I've come up with: /\|[^\|]*africa[^\|]*\|/gi, which says:
\|Match|
[^\|]*Match zero to unlimited instances of any character except|
africaMatchafricaliterally
[^\|]*Match zero to unlimited instances of any character except|
\|Match|
I've tried inserting ((?:\s)|(?!\w)) to make it /\|[^\|]*((?:\s)|(?!\w))africa[^\|]*\|/gi. Although it succeeds in excluding |Mafricano| and |Go Mafricano Go|, it also excludes all other entries except for |West Africa| and |Go Africa Go|. So that is good but it needs to include all single word Africa and its derived forms too.
Can anybody help me?
replace? It should be much more easier.match()function