Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex matching all the giving letter at any position one or multiple times

I’m trying to use a regex that matches all giving letter at any position one or multiple times, for example:

if user the input elol the result should be:

ollie Leola  cello  gello
hello   jello
lobel
lorel   losel
molle   oller

right now I have this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.*elol

but it’s not working because it doesn’t match the letters in different positions in the words

the idea came from this site: https://www.wordhippo.com/what-is/word-finder-unscrambler.html (just search for words in the Containing the letters (in any position) input)

>Solution :

Use look aheads for each letter:

(?=\w*e)(?=\w*o)(?=(?:\w*l){2})\w+

See live demo.

Note that when a letter must appears multiple times, you must add an appropriate quantifier.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading