Boost logo

Boost Users :

Subject: Re: [Boost-users] Problem with regular expression's validity andmatching
From: John Maddock (john_at_[hidden])
Date: 2009-02-24 04:12:51


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


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