I have this code, but it does not seem to be working.
Pattern pattern=Pattern.compile("IMGURSESSION=([0-9a-zA-Z]*);");
Matcher matcher=pattern.matcher("IMGURSESSION=blahblah; path=/; domain=.imgur.com");
System.out.println(matcher.matches());
Would anyone know why?
Matcher#matches() method attempts to match the entire input sequence against the pattern.
Pattern.compile("IMGURSESSION=([0-9a-zA-Z]*);.*$"); //true
Pattern.compile("IMGURSESSION=([0-9a-zA-Z]*);"); //false
the matches Method match against the entire input string.
if you will match only a subsequence you can use the find() method.
the 3 different ways to match with a matcher are explained in the java docs: http://download.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With