I've been searching and testing regex's to match all uris but I can't seem to find one that matches all or most of them. Lots of the ones I've tried throw a compile error. Does anyone have an Xpressive::sRegex compatible regex?
- It throws compile error since it is likely that you include the delimiters, or not escaping the string properly.nhahtdh– nhahtdh2013-01-12 15:59:52 +00:00Commented Jan 12, 2013 at 15:59
- I have this regex, does it look correct? "^([a-z0-9+.-]+):(?://(?:((?:[a-z0-9-._~!$&'()*+,;=:]|%[0-9A-F]{2})*)@)?((?:[a-z0-9-._~!$&'()*+,;=]|%[0-9A-F]{2})*)(?::(\d*))?(/(?:[a-z0-9-._~!$&'()*+,;=:@/]|%[0-9A-F]{2})*)?|(/?(?:[a-z0-9-._~!$&'()*+,;=:@]|%[0-9A-F]{2})+(?:[a-z0-9-._~!$&'()*+,;=:@/]|%[0-9A-F]{2})*)?)(?:\?((?:[a-z0-9-._~!$&'()*+,;=:/?@]|%[0-9A-F]{2})*))?(?:#((?:[a-z0-9-._~!$&'()*+,;=:/?@]|%[0-9A-F]{2})*))?"drwbns– drwbns2013-01-12 16:18:08 +00:00Commented Jan 12, 2013 at 16:18
- Ah ok I found this post - stackoverflow.com/questions/1252992/…drwbns– drwbns2013-01-12 16:19:26 +00:00Commented Jan 12, 2013 at 16:19
- I also have this one - is this correct? "(ftp|http|https):\/\/(\w+\.)*(\w*)\/([\w\d]+\/{0,1})+"drwbns– drwbns2013-01-12 16:24:45 +00:00Commented Jan 12, 2013 at 16:24
- I wanted to mention that the above regex doesn't match anything and I'm also using the regex_search function for matching sub-strings in a stringdrwbns– drwbns2013-01-12 16:35:53 +00:00Commented Jan 12, 2013 at 16:35
| Show 2 more comments
1 Answer
Something you can start from:
using namespace boost::xpressive; static const sregex re = _b >> (s1 = +(~(set= ':', '/', '?', '#'))) >> as_xpr("://") >> (s2 = *(~(set= '/', '?', '#'))) >> (s3 = *(~(set= '?', '#'))) >> !(as_xpr('?') >> (s4 = *(~(set='#')))) >> !(as_xpr('#') >> (s5 = *_)) >> _b;