I want a regeular expression to match a sequence.
The sequence in which i want the regular expression to match is NP so to make sure all the way down the string that after the N there is a P and that before the P there is an N
1) NPNPNPNP = correct
2)NPNPPNP = incorrect
SORRY GUYS I MISSED ONE MORE PART FROM THE QUESTION THE 3RD MATCH WOULD BE
3)NNNPNPNNP = correct SO THERE CAN BE MANY N’s but at the end of the N there has to be a P to follow like above
But i do not think my regular expression is correct, can someone show me where i am going wrong?
std::string a ("NPNPNPPN");
boost::regex const string_matcher("\(NP\)*");
if(boost::regex_match(a,string_matcher))
{
DCS_LOG_DEBUG("Yes it Matches ");
}
else
{
DCS_LOG_DEBUG("No it does not Match");
}
EDIT: updated per the requirements changes and comments & suggestions
Here it is with some tests
Further reading on regular expressions http://www.regular-expressions.info/tutorial.html