Problem
I am trying to to extract words from input
Pacific Gas & Electric (PG&E), San Diego Gas & Electric (SDG&E), Salt River Project (SRP), Southern California Edison (SCE)
I tried doing that online and my pattern (\w\s?&?\s?\(?\)?)
seems to work.
But when I write my Java program, it is not finding it
private static void findWords() {
final Pattern PATTERN = Pattern.compile("(\\w\\s?&?\\s?\\(?\\)?)");
final String INPUT = "Pacific Gas & Electric (PG&E), San Diego Gas & Electric (SDG&E), Salt River Project (SRP), Southern California Edison (SCE)";
final Matcher matcher = PATTERN.matcher(INPUT);
System.out.println(matcher.matches());
}
It returns False
Question
- Why is there a mismatch, seems like my understanding is poor here
- How can I get the words out as groups, meaning
Pacific Gas & Electric (PG&E)
as match group1 and so on