Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a more concise regex to match a-z except for characters e, n, p?

I want to write a regex to match characters a-z except for e, n p. I can write:

[a-df-moq-z]

I'm just wondering if there's a way to write something like ([a-z except ^enp]) just to make the regex more easy to decipher which characters are excluded.

like image 818
neodymium Avatar asked May 28 '13 13:05

neodymium


People also ask

How do you match a character except one?

To match any character except a list of excluded characters, put the excluded charaters between [^ and ] . The caret ^ must immediately follow the [ or else it stands for just itself. The character '. ' (period) is a metacharacter (it sometimes has a special meaning).

Which pattern is used to match any non What character?

The expression \w will match any word character. Word characters include alphanumeric characters ( - , - and - ) and underscores (_). \W matches any non-word character.

Are there different types of regex?

There are also two types of regular expressions: the "Basic" regular expression, and the "extended" regular expression. A few utilities like awk and egrep use the extended expression. Most use the "basic" regular expression.

Which regex matches one or more digits?

+: one or more ( 1+ ), e.g., [0-9]+ matches one or more digits such as '123' , '000' . *: zero or more ( 0+ ), e.g., [0-9]* matches zero or more digits. It accepts all those in [0-9]+ plus the empty string.


1 Answers

You can use negative lookahead like this:

(?![enp])[a-z]

Live Demo: http://www.rubular.com/r/1LnJswio3F

like image 193
anubhava Avatar answered Oct 24 '22 10:10

anubhava