I am using C++ 11's <regex>
support, and would like to check whether the beginning of a string matches a regular expression. [I can switch to Boost if that helps, but my impression is that they're basically the same.]
Obviously if I have control of the actual textual representation of the expression, I can just stick a ^
at the beginning of it as an anchor.
However, what if I just have a regex
(or basic_regex
) object? Can I modify the regular expression it represents to add the anchor? Or do I have to use regex_search
, get the result, and check whether it starts at position 0?
"abc"
is also a regex, but only match the exact string. – Naturalize