MattGotJava MattGotJava - 1 year ago 69
Java Question

How to make a Scanner in Java not care about punctuation

I know how to make a Java Scanner not care about the uppercase or lowercasing, but how do I make it so that it doesn't care about punctuation? I want to do this so that I don't have to type all of this:

if (mirioutput.equalsIgnoreCase("You're an idiot.") ||
mirioutput.equalsIgnoreCase("Your an idiot.") ||
mirioutput.equalsIgnoreCase("You're an idiot") ||
mirioutput.equalsIgnoreCase("Youre an idiot") ||)
//code goes here

By the way, I'm trying to make a Siri-like program that will respond to what you type, if you're wondering why the text says "You're an idiot."

Answer Source

you can remove all none alphabatical and digits characters

      mirioutput = mirioutput.replaceAll("[^A-Za-Z9-0]","");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download