Java regular expressions, find letters from which to form a word


There is a line in which you need to find letters from which you can make a certain word, i.e. each letter must appear at least once.

For example: String s=" oasd c ";

Regular expression to it `

    Pattern pattern = Pattern.compile("c+ & o+");

    Matcher matcher = pattern.matcher(toReturn);

    return matcher.find();`

Doesn't work, should return true but return false How to write an expression that will check a string where each letter that will be specified occurs one or more times. I tried it in different ways, it took an hour.


Positive Lookahead can be used. For example, for the expression


and test suite

мама мыра раму
мама мыра ртаму

lines will be matched

мама мыра ртаму
Scroll to Top