Matching strings using regular expressions
Let's do something useful! It is a common case when the user's input must be checked using some regular expression. The problem is that there are a lot of regular expression syntaxes, expressions written using one syntax are not treated well by the other syntaxes. Another problem is that long regexes are not so easy to write.
So in this recipe, we are going to write a program that supports different regular expression syntaxes and checks that the input strings match the specified regexes.
Getting started
This recipe requires basic knowledge of standard library. Knowledge of regular expression syntaxes can be helpful.
Linking examples against the boost_regex
library is required.
How to do it...
This regex-matcher example consists of a few lines of code in the main()
function:
- To implement it, we need the following headers:
#include <boost/regex.hpp> #include <iostream>
- At the start of the program, we need to output the available regex syntaxes...