mardi 7 janvier 2020

Using regex in java to get a word from a string

I need to find the word "best" in a string using regex but it's throwing a "no match found" error. What am I doing wrong?

Pattern pattern = Pattern.compile("(best)");
String theString = "the best of";
Matcher matcher = pattern.matcher(theString);
matcher.matches();
String whatYouNeed = matcher.group(1);
Log.d(String.valueOf(LOG), whatYouNeed);

Aucun commentaire:

Enregistrer un commentaire