I am trying to use String.replaceAll(regex, String) to replace some chars from a String.
My string is some html and I've been trying to replace 'width: xxxxx.xxxpx;' width 'width: auto;'.
I came up with 2 reg expressions which according to an online reg tester works fine as:
width: [0-9]{3,}px; -- match at least 3 digits followed by px;
width: [0-9]{3,}.[0-9]{1,}px; -- match at least 3 digits followed by any char (in my case a .) followed by at least 1 digit and finally px;
This has been used in this way in my code:
text = text.replaceAll("width: [0-9]{3,}px;", "width: auto;");
text = text.replaceAll("width: [0-9]{3,}.[0-9]{1,}px;", "width: auto;");
as an example, I used this text:
<p style="margin-left: 10px;"><br></p><p style="margin-left: 10px;">text <span style="text-decoration-line: underline;">not</span> not text.</p><div class="ui-resizable-handle ui-resizable-n" style="width: 1404.8px; z-index: 90;"></div><div class="ui-resizable-handle ui-resizable-w" style="height: 100.8px; z-index: 90;"></div><div class="ui-resizable-handle ui-resizable-e" style="height: 100.8px; z-index: 90;"></div><div class="ui-resizable-handle ui-resizable-s" style="width: 1404.8px; z-index: 90;"></div><table class="ui-resizable" style="width: 1405.6px; border: 1px solid black; margin-left: auto; margin-right: auto;"><tbody><tr><td class="ui-resizable" style="padding: 10px; border: 1px solid black;">in my opinion both this text is wrong;<br><br><br><div class="ui-resizable-handle ui-resizable-e" style="height: 99.2px; z-index: 90;"></div><div class="ui-resizable-handle ui-resizable-s" style="width: 1404px; z-index: 90;"></div></td></tr></tbody></table><p style="margin-left: 10px;">other text: </p><table class="ui-resizable" style="width: 1422.4px; border: 1px solid black; margin-left: auto; margin-right: auto;"><tbody><tr><td class="ui-resizable" style="padding: 10px; border: 1px solid black;"><p><br></p><p><br></p></td></tr></tbody></table>
But this is not working. What am I doing wrong, please?
question from:
https://stackoverflow.com/questions/65849198/regex-creation-to-be-used-on-replaceall 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…