So I have this snippet of Java code:
Pattern p = Pattern.compile("* bar");
Matcher m = p.matcher("foo bar");
System.out.println(m.find());
However when I run it I get the following error:
Exception in thread "main" java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0 * bar ^
Not sure why this happens as when I replace Pattern p = Pattern.compile("* bar") with Pattern p = Pattern.compile("foo *")
everything works as expected and the console outputs true.