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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:
(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_castit to an integer, and use that to validate theaaaaapart.