Skip to main content
dublove
Legend
May 25, 2025 8:10 AM UTC
Answered

How to find 24 letters except m and p using regular expressions?

Is it only [a-ln-oq-z]?

It seems unscientific and too much of a hassle.

Eugene TysonCorrect answer
Community Expert
May 28, 2025 5:49 PM UTC

If you want to find just lowercase latin characters

This skips numbers

(?=[a-z])(?![mp]).

 

If you want to include upper and lowercase

(?i)(?=[a-z])(?![mp]).

 

If you want to inclue any letter from any lanaguge not just latin a-z

(?=\p{L})(?![mp]).

again add (?i) at the start if you want to inlude upper and lower case

 

This should only catch a-z and not numbers or any other characters

 

But if you want all characters a-z in all languages then use \p{L}

14 replies

m1b
Community Expert
Community Expert
May 25, 2025 8:33 AM UTC

@dublove I think that is the best way. You can also do

[^mp]

but that will find every character except m and p.

 

So what you have is fine, and probably optimal.

- Mark

 

P.S. can you please double check the translation of "unscientific"—we don't use it that way. Perhaps you mean "inefficient" or "clumsy"? "Scientific" means about science, so unscientific just means not about science or, more often, about pseudo-science.

Translate
dublove
dubloveAuthor
Legend
May 25, 2025 9:46 AM UTC

Yes, I'm "unscientific" in the sense of being inefficient.
But it's more focused on “not the best thinking or techniques”.

Translate
m1b
Community Expert
Community Expert
May 25, 2025 9:49 AM UTC

Yes I thought so. It would be appropriate to use "inelegant", which is often used to describe code that isn't "elegant".

Translate