Skip to main content
dublove
Legend
May 25, 2025
Answered

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

  • May 25, 2025
  • 1 reply
  • 906 views

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

It seems unscientific and too much of a hassle.

Correct answer Eugene Tyson

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}

1 reply

m1b
Community Expert
Community Expert
May 25, 2025

@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.

dublove
dubloveAuthor
Legend
May 28, 2025

@m1b 

I found a weird way that it works. But I wonder if it could be a pitfall?

[^a-z]|[^mp]

 

It doesn't seem right either, in fact it's just [^mp]

m1b
Community Expert
Community Expert
May 28, 2025

Yes that won't be much help. It finds any character that isn't lowercase a-z followed by any character that isn't m or p.

 

So it would match "55" or "TV" or two tab characters.