'Matcher doesn't return the matched regex, instead returns whole string in group(0) (Java)
The problem I'm facing is that upon following the question at this link, Using Regular Expressions to Extract a Value in Java, I am unable to extract the correct group of the String
Pattern p = Pattern.compile("I have .*");
Matcher m = p.matcher("I have apples");
if(m.find()){
System.out.println(m.group(0));
}
What I get:
I have apples
What I want to get:
apples
I've tried asking for m.group(1) as well but it throws me an exception.
How should I go about this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
