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:
.*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.