Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Guide ,
May 25, 2025 May 25, 2025

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

It seems unscientific and too much of a hassle.

TOPICS
Bug , How to , Scripting , Type
494
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 28, 2025 May 28, 2025

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}

Translate
Community Expert ,
May 25, 2025 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 25, 2025 May 25, 2025

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2025 May 25, 2025

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 28, 2025 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]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 28, 2025 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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 28, 2025 May 28, 2025

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}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 28, 2025 May 28, 2025

牛B

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 28, 2025 May 28, 2025

No idea what this reply is about

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 28, 2025 May 28, 2025

you're so powerful that you have no enemies.
You're so strong it's hard to believe.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 28, 2025 May 28, 2025

Thank you - very nice words

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2025 May 29, 2025

Hi @Eugene Tyson I've learned from you. I have never seen that configuration of positive and negative lookarounds together. Very clever!

- Mark

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2025 May 29, 2025

Finally, I've taught you something! Marking this one in the diary!

 

I think it's classed as a 'lookaround' 

(?=[a-z])
This is a positive lookahead it asserts that what follows the current position is a lowercase letter from a to z.

(?![mp])
This is a negative lookahead it asserts that what follows is not an m or a p.

 

And that's my explanation and I'm sticking to it.

 

Then of course you need the any character '.' to fulfill a search to match any character matching/not matching that description. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2025 May 29, 2025

Also the \p{L} token I haven't seen before, and is much nicer than the POSIX nonsense., haha. I also saw there is \P{L} which is the inverse, and can see uses for that, too. Thanks again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 29, 2025 May 29, 2025
LATEST

Yeh - @Peter Kahrel put me on to these recently - some work and some don't, I bookmarked this page. 

 

https://www.regular-expressions.info/unicode.html

 

For example \p{P} doesn't work unless it's \p{P*} for punctuation 

 

I've been dabbling more and more since. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines