Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regular expressions missing out certain letters

Tags:

regex

php

Is there a simple way to ignore/miss out certain letters. The problem is find a word that is 5 letters long but does not contain the letters b,j,m or n.

Can I simply only specify the letters I do want such as [a][c-i][k-l][o-2]? This doesn't appear very clean and I still need to specify the word needs to be 5 letters long. So I guess I need a /w and a {5} but am not sure how to combine it all. Thanks.

like image 342
s2 8v Avatar asked May 14 '13 14:05

s2 8v


1 Answers

This selects all characters except bjmn:

[^bjmn]{5}

If you want only lower case letters except those you listed:

[c-ik-lo-za]{5}

If you don't want 5-letter-words that are part of longer words, add word boundary checking:

\b[c-ik-lo-za]{5}\b
like image 100
tomsv Avatar answered Sep 28 '22 11:09

tomsv