Suppose I wanted to create a boost.regex expression that would match strings such as
"repetitions: 5 aaaaa" "repetitions: 3 aaa"
Is there a way to do this with boost?
Suppose I wanted to create a boost.regex expression that would match strings such as
"repetitions: 5 aaaaa" "repetitions: 3 aaa"
Is there a way to do this with boost?
I haven't used boost::regex in particular, but the regular expression you're asking for is straight-forward. Looking through the boost::regex docs, it looks like you'd do something similar to this:
boost::regex e("repetitions:\\s+\\d\\s+[a-zA-Z]+");
(double slashes are so the escape sequences aren't swallowed by the compiler)
Note:
If you're also trying to validate that the first number matches the number of letter 'a', that won't work with just a regular expression. Regexes only match characters, without any clue as to what they mean, so '5' and '3' are not seen in any numerical way. Look at their docs on Captures. You'll want to get the number as a string, lexical_cast
it to an integer, and use that to validate the aaaaa
part.