There is an HTML letter template and a regular expression that works for regex101.com . With its help, instead of the specified variables in the %name% format, the necessary values ​​are substituted. I have several such variables in the document.

The problem is that Matcher takes the first and last % and supposedly this one found a match by a regular expression.

The regular expression itself looks like this: %([az].+)% . The most interesting thing is that everything works fine on regex101.com , but not in the code.

Tell me the solution.

  • one
    Use %([az]+)% - Wiktor Stribiżew
  • @ WiktorStribiżew Thank you. helped - Tsyklop

1 answer 1

Pattern .+ Finds 1 or more characters other than line feeds. Since + is a “greedy” quantifier, the sequence of characters from the leftmost to the rightmost in the string is saved in the match.

Remove .+ And use

 %([az]+)% 
  • % - percent symbol
  • ([az]+) is a fascinating group (mask) that finds 1 or more lower-case ASCII letters
  • % - percent symbol