Reputation: 363
I need a regular expression to find two consonants together between two vowels but these consonants should not be in a list:
For instance, my black-list is (br|bl|cn|cr)
between = It's good because 'tw' is not in the list.
abroad = it's wrong because 'br' is in the black-list.
But I need only the two last pair consonant-vowel:
between = I only need 'we' no 'et'.
I have the following regex, but I don't know how to check if the captured consonant is in the list.
"[aeiou]([^aeiou]{2})[aeiou]"
I captured the consonants with "([^aeiou]{2})", but how do I check if the capture "\1" is in the black-list?
Upvotes: 1
Views: 207
Reputation: 627086
You can use
(?<=[aeiou](?!(?:br|bl|cn|cr))[b-df-hj-np-tv-z])[b-df-hj-np-tv-z][aeiou]
(?<=[aeiou](?!(?:b[rl]|c[nr]))[b-df-hj-np-tv-z])[b-df-hj-np-tv-z][aeiou]
See the regex demo
Details
(?<=[aeiou](?!(?:br|bl|cn|cr))[b-df-hj-np-tv-z])
- a positive lookbehind that requires a lowercase ASCII vowel letter and then an ASCII lowercase consonant letter that is not a starting point of a br
, bl
, cn
or cr
char sequences[b-df-hj-np-tv-z]
- a consonant lowercase ASCII letter[aeiou]
- a lowercase ASCII vowel letterUpvotes: 1