• Source
    1. import java.util.regex.*;
    2.  
    3. class Test
    4. {
    5. public static void main (String[] args) throws java.lang.Exception
    6. {
    7. String s = "both 56% as well as 30-60%.";
    8. Pattern pattern = Pattern.compile("\\b(?:\\d+[—–-])?\\d+(?:%|percent\\b)");
    9. Matcher matcher = pattern.matcher(s);
    10. while (matcher.find()){
    11. System.out.println(matcher.group());
    12. }
    13. }
    14. }