I want to check if the String string contains an "= " and that "= " is followed by an alphanumeric character. For example:
String cadena1 = "= 'hola"; //patron.matcher(cadena1); devuelve false
String cadena2 = "= hola"; //patron.matcher(cadena2); devuelve true
String cadena3 = "= 1"; //patron.matcher(cadena3); devuelve true
The regex I am using is:
Pattern patron = Pattern.compile("=\\s[\\w]");
Matcher matcher = patron.matcher(cadena);
The expression is fine, you have to call the
find()
matcher method to find the first match:You should use it like this, using the find() method: