import java.util.*;
public class ReplaceString {
public static void main(String[] args) {
new ReplaceString().run();
}
public void run()
{
System.out.println("Input String:\n");
Scanner keyboardScanner = new Scanner(System.in);
String inString = keyboardScanner.nextLine();
String strOutput = inString.replace("is","was");
System.out.println(strOutput);
}
}
I am trying to replace all occurences of “is” with “was” from an inputted line, which I was able to do but I do not want to mess the words where “is” is a part of the word.
For example any occurence of word nameis or this should be ignored. Only individual occurences of “is” should be replace with “was”
I know I can use regular expressions but i dont know the format if that regex
Try
reference link
Test output:
output