Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2006-02-09 05:41:22

> But I made a expirementation and found that "^cde" couldn't neither
> match "cdefg", nor "abcde",

^cde will *find* a match in cdefg if you call regex_search, it will not
succeed if you call regex_match however as that requires *all* of the string
to be matched. "abcde" will never be matched by ^cde.

> Anchors:
> A '^' character shall match the start of a line.
> A '$' character shall match the end of a line.
> I still can't understand it exactly, if "^cde$" only matches "cde",
> why we need to write the regex as "^ced$"?

What? ^cde$ will match the characters "cde" *only* if:

1) The "c" was preceeded by a line break character, or the "c" was the first
character in the string.


2) The "e" character is followed by a line break character or is the last
character in the string.

So using regex_search the following strings contain matches for ^cde$ :


However, using regex_match only the first of those strings would be matched.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at