Problem with regular expression's validity and matching

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; . . . } }

AMDG Paulino De Assis Fong wrote:
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.
How do you create the regex? std::wstring csRegex(L"((\(\d{3}\)?)|(\d{3}))([\s-./]?)(\d{3})([\s-./]?)(\d{4})") won't work because the \'s are handled by the compiler before they get to the regex library. In Christ, Steven Watanabe

std::wstring csRegex(L"((\(\d{3}\)?)|(\d{3}))([\s-./]?)(\d{3})([\s-./]?)(\d{4})")
Hi Steve, I didn't hardcode the value like the example you pointed out. I read the value from a CDATA section in an xml document so the value should be probably escaped and stored in csRegex, which is a CString. Thanks Steven Watanabe <watanabesj <at> gmail.com> writes:
How do you create the regex?
std::wstring csRegex(L"((\(\d{3}\)?)|(\d{3}))([\s-./]?)(\d{3})([\s-./]?)(\d{4})")
won't work because the \'s are handled by the compiler before they get to the regex library.
In Christ, Steven Watanabe

AMDG Paulino De Assis Fong wrote:
std::wstring csRegex(L"((\(\d{3}\)?)|(\d{3}))([\s-./]?)(\d{3})([\s-./]?)(\d{4})")
Hi Steve,
I didn't hardcode the value like the example you pointed out. I read the value from a CDATA section in an xml document so the value should be probably escaped and stored in csRegex, which is a CString. Thanks
Ok. The problem is [\s-./]. '-' is a special character inside []. This is true for perl as well: C:\boost\trunk>perl my $x = "test-test"; $x =~ s/[t-e]{3}/x/; Invalid [] range "t-e" in regex; marked by <-- HERE in m/[t-e <-- HERE ]{3}/ at - line 2. In Christ, Steven Watanabe

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.
How are the expressions entered in the program? If they're string literals then don't forget that you need to double up those backslashes (once for the compiler, once for the regex engine): const char* re = "((\\(\\d{3}\\)?)|(\\d{3}))([\\s-./]?)(\\d{3})([\\s-./]?)(\\d{4})"; HTH, John.
participants (3)
-
John Maddock
-
Paulino De Assis Fong
-
Steven Watanabe