I have 2 Scenarios:
- String Starts with Sample Country ! i.e. Sample Country ! Test Data
I want a regex to replace Sample Country ! with Empty String, Country here is not fixed, it can be US, France etc
I tried:
System.out.println(str.replaceAll("^(Sample[^!]+!)", ""));
I am getting the Output
! Test Data
whereas I just want
Test Data
String ends with Sample Country ! i.e. Test Data Sample Country ! here also I just want
Test Data
Can someone help to provide the correct Regular expression with the explanation. Thanks a lot