I wanted to do some
pattern detection using regular expressions, so I went to "http://docs.oracle.com/javase/7/docs/api" and looked up class {String} and scrolled down to the section for method {matches()}, where the documentation said, "Tells whether or not this
string matches the given regular expression." I clicked on "regular expression", and that took me to the page for class {Pattern}, down to the section labeled <Summary of regular-expression constructs>. I scrolled even further down to the subsection labeled <Boundary matchers>. The caret was listed as a boundary matcher for "The beginning of a line", and the dollar sign was listed as a boundary matcher for "The end of a line". So I wrote the following code:
I expected the call to {actual.matches( expectedOne)} to return {true}, because it had no dollar sign at the end, so it wasn't anchored on the end. But it returned {false}. The call to {actual.matches( expectedTwo)} did return {true}. What's the use of the two anchors, caret and dollar sign, if regular expressions have to have a ".*" at the end, if you want to match a prefix of the line? I mean, I could have written the code:
without the carets, and it would have had the same effect. So why even have the two anchors?
Kevin S