I'm trying to write a regex that finds times at the beginning of a string. I want to remove that part of the string so I'm using the regioEnd function but it sets the regioend to the end of the line.
Pattern pattern = Pattern.compile("\\d+.\\d+");
String line = "4:12testline to test the matcher!";
System.out.println(line);
Matcher matcher = pattern.matcher(line);
int index = matcher.regionEnd();
System.out.println(line.substring(index));
What am I doing wrong here?
It looks like you want to use just end()
instead of regionEnd()
. The end()
method returns the index of the first character past the end of whatever the regular expression actually matched. The regionEnd()
method returns the end of the area where the matcher searches for a match (which is something you can set).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With