- #1
swuster
- 42
- 0
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]"));
}
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: