Friday 30 August 2013

java regex what the heck? am I misreading the regex docs completey?

java regex what the heck? am I misreading the regex docs completey?

System.out.println("a".matches("^[A-Za-z]+"));
System.out.println("a ".matches("^[A-Za-z]+"));
This gives me:
true
false
What the heck is up? As far as I am reading it, "[A-Za-z]" includes "a",
and "+" means one or more, so this seems like it would work, at least in
this universe....
Details are:
Mac OS X 10.8.4
$ java -version
java version "1.6.0_51"
Java(TM) SE Runtime Environment (build 1.6.0_51-b11-457-11M4509)
Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-457, mixed mode)
Maybe I have been writing perl too long and java's regex system is kind of
like it but not? No idea.

No comments:

Post a Comment