Boost logo

Boost Users :

Subject: [Boost-users] Problem with regular expression's validity and matching
From: Paulino De Assis Fong (fongph_at_[hidden])
Date: 2009-02-23 20:02:49


Hi,

I have two problems that I would need some help. Thanks in advance.

Question 1:

Please consider the regular expression to match US phone number below:

((\(\d{3}\)?)|(\d{3}))([\s-./]?)(\d{3})([\s-./]?)(\d{4})

boost doesn't like it and it will throw an exception for the code below while
it seems to be fine in online regex tester and .Net Regex library. I don't
know what is imcompatiable with boost regex library. Please advice.

try
{
        boost::wregex expr(csRegex, boost::regex::normal |
boost::regbase::icase);
}
catch (boost::exception const& e)
{
}

Question 2:

Please consider the regular expression to match US SSN below:

(?!000)([0-6]\d{2}|7([0-6]\d|7[012])) ([ -])? (?!00)\d\d([ -|])? (?!0000)\d{4}

It didn't throw an exception for this regular expression but it wasn't able to
match any SSN at all in any format while it matches fine using other regular
expression engine. Am I missing something?

if (expr.expression())
{
        // Boost Regex usage flags
        boost::regex_constants::match_flag_type flags =
boost::regex_constants::match_normal;

        // Start the boost regular expression iterator
        boost::wcregex_iterator start(boost::make_regex_iterator
(StringToMatch, expr, flags)), end;

        while (start != end)
        {
              boost::match_results<const wchar_t*> match = *start;
              .
              .
              .
        }
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net