Please check following code.
Pattern pxPattern = Pattern.compile("^.*[0-9]+(%|pt|em).*$");
Matcher pxMatcher = pxPattern.matcher("onehellot455emwohellothree");
System.out.println(pxMatcher.matches());
System.out.println(pxMatcher.group(0));
i want to substract string 445em. i am using code for checking css. means i wants to extract
just values like 45em or 50%.
Thanks.
First, the captured group is in group 1, not group 0. Then you need to modify your regex to not consume the numbers and include them in the group. Try:
EDIT:
To get all values from a string with several, you can use this pattern: