If I have two strings .. say
string1="Hello dear c'Lint and dear Bob"
and
string2="dear"
I want to Compare the strings and delete the first occurrence of matching substring ..
the result of the above string pairs is:
Hello c'Lint and dear Bob
This is the code I have written which takes input and returns the matching occurence:
System.out.println("Enter your regex: ");
BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
String RegEx = bufferRead.readLine();
Pattern pattern = Pattern.compile(RegEx);
System.out.println("Enter input string to search: ");
bufferRead = new BufferedReader(new InputStreamReader(System.in));
Matcher matcher = pattern.matcher(bufferRead.readLine());
boolean found = false;
while (matcher.find()) {
System.out.println("I found the text:\"" + matcher.group() +
"\" starting at index \'" +
matcher.start() +
"\' and ending at index \'" +
matcher.end() +
"\'");
}