I am trying to match input data from the user and search if there is a match of this input.
for example if the user type : A*B*C*
i want to search all word which start with A and contains B and B
i tried this code and it;s not working:(get output false)
public static void main(String[] args)
{
String envVarRegExp = "^A[^\r\n]B[^\r\n]C[^\r\n]";
Pattern pattern = Pattern.compile(envVarRegExp);
Matcher matcher = pattern.matcher("AmBmkdCkk");
System.out.println(matcher.find());
}
Thanks.
I thing you should use
*modifier in your regex like this (for 0 or more matches between A & B and then between B & C):EDIT: It appears that you’re working off the input coming from your user where user can use asterisk
*in inputs. If that is the case consider this:Where
userInputis String like this: