I intends to use REGEX in Java to match a String. For e.g.I have letters 'A' 'A' 'A' 'P' 'P' 'L' 'E' 'S'
.
I want to check whether a string contains 0-3 'A', 0-2 'P', 0-1 'L', 0-1 'E' and 0-1 'S'
.
Examples of string which shall pass the check:
APPLE, APPLES, ALE, PALE... etc
This is what I've tried:
if (str.matches("[A]{0,3}[P]{0,3}[L]{0,1}[E]{0,1}[S]{0,1}"))
APPLES successfully passed through the check but not SAPPLE.