I would like to remove everything(for the chars like {}$* \w+ "") which is between ; and #:
For example I would like to remove from this string:
Input:
OR(AND(CA18*CB18);M10#;ABZZ/kld // remove ;M10#
Output:
OR(AND(CA18*CB18);ABZZ/kld
I tried it with this regular expression:
^[;]\w+([A-Za-z0-9])[#]
However, this does not seem to work any recommendations?
Try this solution:
String input = "OR(AND(CA18*CB18);M10#;ABZZ/kld"; // remove ;M10#
// using String.replaceAll here instead of Pattern/Matcher
//
// | starts with ; included
// || any character, reluctantly quantified
// || | ends with # included
// || | | replace all instances with empty
// || | | string
System.out.println(input.replaceAll(";.+?#", ""));
Output
OR(AND(CA18*CB18);ABZZ/kld
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