-1

I am making a simple regex to determine integers of length 1-4 from string my regex is:

\d{1,4}

My Regex is valid in all online regex testing sites such as regex101 but Android studio is not accepting this Regex please find image here.

I need your help in finding any silly mistakes in this. Sample:

Regex: \d{1,4}
String: dgsdfg700
Match: 700

Please tell where am I doing wrong so studio is not accepting my regex and all other sites are.

MY code:

Pattern pattern = Pattern.compile("\\d{1,4}");

            Matcher matcher = pattern.matcher(mystring);
            if (matcher.find())
            {
             //my stuff here
            }

1 Answers1

1
public boolean isValid(final String pass){
        Pattern pattern;
        Matcher matcher;
        final String PASS_PATTERN = "^[0-9]{1,4}$";
        pattern = Pattern.compile(PASS_PATTERN);
        matcher = pattern.matcher(pass);

        return matcher.matches();
    }
avinash
  • 29
  • 4