Simple question about regexps.
I’ve got
String text = "foobar1foobar1";
And I need to get part before first 1 (foobar)
When I do something like that:
Pattern date_pattern = Pattern.compile("(.+)1");
Matcher matcher = date_pattern.matcher(text);
matcher.group(1);
But I recieve “foobar1foobar”.
The
+quantifier is greedy so it matches as much as possible. You should the reluctant version of this quantifier+?; your pattern then becomes: