Skip to content

Instantly share code, notes, and snippets.

@jido
Last active June 29, 2016 23:10
Show Gist options
  • Save jido/878ee71ca908366ff193783bbdce0c11 to your computer and use it in GitHub Desktop.
Save jido/878ee71ca908366ff193783bbdce0c11 to your computer and use it in GitHub Desktop.
Why is my Matcher not working?
private static final Pattern parser = Pattern.compile("/(\\S+)/");
private String parseAction(String tag) {
Matcher them = parser.matcher(tag);
if (!them.find()) return "YOLO";
return them.group(1);
}
Result:
juin 29, 2016 11:58:24 PM com.bredelet.mistigri.Mistigri prrcess
INFOS: tag=<> action=YOLO
juin 29, 2016 11:58:24 PM com.bredelet.mistigri.Mistigri prrcess
INFOS: tag=<CAPS text="Mistigri"> action=YOLO
juin 29, 2016 11:58:24 PM com.bredelet.mistigri.Mistigri prrcess
INFOS: tag=<CAPS text="quite friendly"> action=YOLO
juin 29, 2016 11:58:24 PM com.bredelet.mistigri.Mistigri prrcess
INFOS: tag=<#CAPS> action=YOLO
juin 29, 2016 11:58:24 PM com.bredelet.mistigri.Mistigri prrcess
INFOS: tag=</CAPS> action=YOLO
@jido
Copy link
Author

jido commented Jun 29, 2016

Don't put the regex inside / /.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment