It is necessary between the tags to replace e with E and z with Z , for example.
String s= "<pre><code>еееееееееееzzzzzzzzzzzzzz</code></pre>"; String startTag = "<pre><code>"; String endTag = "</code></pre>"; Pattern pattern = Pattern.compile(startTag + "(.*?)" + endTag); Matcher matcher = pattern.matcher(s); while (matcher.find()) { s = s.replace(matcher.group(0), startTag + matcher.group(1).replace("z", "Z").replace("е", "Ё") + endTag); } System.out.println("\nПосле изменения: \n" + s); Displays everything correctly:
<pre><code>ЁЁЁЁЁЁЁЁЁЁЁZZZZZZZZZZZZZZ</code></pre> It is necessary to add \ n anywhere in the condition (to the variable s ), as the implementation stops working:
s= "<pre><code>ееее\nеееееееzzzzzzzzzzzzzz</code></pre>"; will issue:
<pre><code>ееее еееееееzzzzzzzzzzzzzz</code></pre> those. - without changes. What am I doing wrong? I will not think.
- On this site I found a similar article ( Migrating in a regular expression ), but the answers were not thorough.