-1

In my text On Android, I want to extract all the digit that are, for example, They are from 15 to 20 digits , from the text according to a special pattern. Like method findall() in Python:

re.findall(r"\d{15,20}", r.text)
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
imna
  • 21
  • 6

1 Answers1

1

You can try to use the next code snippet:

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegExp{
    public static void main(String[] args) {
        String text = "test with 111222333444555, 12345 and 11223344556677889900 numbers";
        // matches digits that are between 15 to 20 digits long
        String pattern = "\\d{15,20}"; 
        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher(text);

        while (m.find()) {
            System.out.println(m.group());
        }
    }
}
Aksen P
  • 4,564
  • 3
  • 14
  • 27