A notation like “ \w?” becomes !_w with Boost.Xpressive because the exclamation mark must be prefixed.īoost.Xpressive supports actions that can be linked to expressions – something Boost.Regex doesn’t support. Since the question mark isn’t a valid operator in C , Boost.Xpressive replaces it with the exclamation mark. For example, the question mark is a meta character in regular expressions to express that a preceding item is optional. The plus sign is an unary operator, which in C must be put in front of an object.īoost.Xpressive emulates the rules of regular expressions as much as they can be emulated in C . While the syntax of regular expressions expects that quantifiers are put behind character groups – like with “ \w ” – the plus sign must be put in front of _w. To express that at least one alphanumeric character should be found, _w is prefixed with a plus sign. Boost.Xpressive provides the operator operator>, which is used in Example 9.3. Otherwise, the result wouldn’t be valid C code. While “ \w” and “ \s” can be written one after another in a string, objects like _w and _s must be concatenated with an operator. For example, the object _w is similar to “ \w”. The library provides objects for character groups. Both examples search for at least one alphanumeric character followed by one space followed by at least one alphanumeric character.īoost.Xpressive makes it possible to write regular expressions with C code. It is exactly the same regular expression. Compare this with Example 9.2, where the regular expression is applied to a string of type const char*. Because s is based on std::string in Example 9.1, the type of the regular expression must be boost::xpressive::sregex. The type of the regular expression in Boost.Xpressive depends on the type of the string being searched. However, there is a fundamental difference between Boost.Xpressive and Boost.Regex. You can see this in Example 9.1, which uses the function boost::xpressive::regex_match(), and which looks similar to Example 8.1. boost::xpressive::regex_match() compares strings, boost::xpressive::regex_search() searches in strings, and boost::xpressive::regex_replace() replaces characters in strings. Std::cout << std::boolalpha << regex_match(s, expr) << '\n' īoost.Xpressive basically provides the same functions as Boost.Regex, except they are defined in the namespace of Boost.Xpressive.
0 Comments
Leave a Reply. |