Lafix
Lafix

Reputation: 389

Regular expression: matching a string of a certain length that contains specific letters?

Now I need this regular expression to match only strings of a certain length that contain several specific letters, it should work as follows:

If I want a 10-letter word with at least one p, one o, one m, one s, one t, one h, and one u in it.

\b(regex inserted)\b

This expression should only match words such as "posthumous" "Prometheus", while other 10-letter words like "paranormal" won't be a match.

I racked my brain for a good ten minutes with no luck, I think it must have been some syntax I have yet to learn.

All suggestions would be greatly appreciated, many thanks!

Upvotes: 2

Views: 2888

Answers (1)

vks
vks

Reputation: 67968

^(?=.*p)(?=.*o)(?=.*m)(?=.*s)(?=.*t)(?=.*h)(?=.*u).{10}$

Try something like this.This will work.

See demo.

http://regex101.com/r/yR3mM3/22

Upvotes: 1

Related Questions