Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to match all alphabet except few?

Tags:

regex

pcre

I want to match [a-z] only except the letters a,e,i,o,u

Using negated set [^aeiou]* I could match everything except a,e,i,o,u, but how to restrict my everything to [a-z]?

This can be easily done using character class subtraction ([a-z-[aeiou]]) in XML Schema, XPath, .NET (2.0+), and JGsoft regex flavors, but how can I do it in PCRE?

like image 562
karthik manchala Avatar asked Apr 25 '15 01:04

karthik manchala


1 Answers

You could use negative lookahead assertion. It's like a kind of subtraction.

(?![aeiou])[a-z]
     ^        ^
     |        |
subtract    from

DEMO

like image 164
Avinash Raj Avatar answered Nov 02 '22 09:11

Avinash Raj