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

For example: String s=" oasd c ";

Regular expression to her `

  Pattern pattern = Pattern.compile("c+ & o+"); Matcher matcher = pattern.matcher(toReturn); return matcher.find();` 

It does not work, it should produce true, but it gives false How to write an expression that checks the line where each letter is indicated to meet one or several times. I tried differently, I was dug for an hour.

  • What kind of regular is this? It will correspond to the line cccccccccccccccc & ooooo , but not the same as in your example. Do you want to find the letters c and o in the example regularly? Ampersand is not a special character in regular expression. You probably want something like .*c.*|.*o.* O. .*c.*|.*o.* - iksuy
  • I know that this symbol is not in regular expressions, I have designated what I would like to receive, but I do not know how to write it, your code is incorrect, because OR OR, and if any of these letters will not, the word will not be . - fxrbfg
  • Do you need regulars? Something tells me that you have to write all possible combinations of letters. For example, for the letters c and o - (.*o.*c.*)|(.*c.*o.*) O. (.*o.*c.*)|(.*c.*o.*) O. (.*o.*c.*)|(.*c.*o.*) - Vartlok
  • And you do not search for hieroglyphs? Of these, too, the words make up. Chinese, Japanese there ... - Sergey
  • Any word? Or do you have a given word to be compiled (or a dictionary of such words)? - avp

1 answer 1

You can use Positive Lookahead. For example, for the expression

 (?=.*м)(?=.*а)(?=.*р)(?=.*т)(.*) 

and test suite

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

lines will be patched

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