I know there's a million and one question & answers on Regex but I can't seem to find a straight-forward one that helps me solve this problem while also understanding it.
I want to take a String and ignore anything in the String that is between two quotes. For example,
String myString = "(\"You entered a value of \" + moneyAmount + \"
dollars.\");";
How do I get it so anything between quotes ("You entered a value" and "dollars.") is forgotten? I would want my new String to be:
( + moneyAmount + );
Thank you and please help me understand regez!!
You could use \".*?\" (but you have to escape the literal backslash and the quote, so it looks it a little funky). Like,
System.out.println(myString.replaceAll("\\\".*?\\\"", ""));
Outputs (as requested)
( + moneyAmount + );