1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to process a String with regexes in Java?

  1. Sep 7, 2009 #1
    I'm attempting to write a relatively simple method. It needs to search through a String for any characters that are not specifically 'A', 'I', 'O', and 'C', returning false if it runs across any other characters besides those four. The string I'm processing could be hundreds/thousands of characters long, so I'm trying to avoid using a loop if possible.

    I know that I can use a regular expression like [^AIOC] to do this but I'm not sure how. Class String has a method matches() which accepts a regex String as an argument but I believe it only matches the entire string and not the individual characters. Am I doing it wrong? Appreciate the feedback.

    Thinking of using something like this, except I know that matches doesn't work that way. I need something more like find():
    public boolean checkLine(String line) {
    return !(line.matches("[^ACIO]"));
    }
     
    Last edited: Sep 8, 2009
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: How to process a String with regexes in Java?
  1. String in java (Replies: 7)

Loading...