Can anyone help me with creating a regex for variables in java so that the string variable will be considered to be a case insensitive and replace each and every word like Access, access, etc with WINDOWS of any thing like that?
This is the code:
$html=html.replaceAll(label, "WINDOWS");
Notice that label is a string variable.
Just add the "case insensitive" switch to the regex:
html.replaceAll("(?i)"+label, "WINDOWS");
Note: If the label could contain characters with special regex significance, eg if label was ".*"
, but you want the label treated as plain text (ie not a regex), add regex quotes around the label, either
html.replaceAll("(?i)\\Q" + label + "\\E", "WINDOWS");
or
html.replaceAll("(?i)" + Pattern.quote(label), "WINDOWS");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With