In Java, I want to replace all *
characters with \*
.
Example:
Text: select * from blah
Result: select \\* from blah
public static void main(String[] args) {
String test = "select * from blah";
test = test.replaceAll("*", "\\*");
System.out.println(test);
}
This does not work, nor does adding a escape backslash.
Press Ctrl+H to open the Find and Replace dialog box. Click the More button to show more find/replace options. Select the Use wildcards checkbox. Click Find Next to find the first instance, then Replace to replace the multiple asterisks with a paragraph mark.
I figured it out
String test = "select * from blah *asdf";
test = test.replaceAll("\\*", "\\\\*");
System.out.println(test);
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