2013-01-12 52 views
0

我一直在尋找和測試正則表達式匹配所有uris,但我似乎無法找到匹配所有或大多數uris的匹配項。很多我嘗試過的都會拋出編譯錯誤。有沒有人有一個Xpressive :: sRegex兼容的正則表達式?Boost :: Xpressive :: sregex uri模式匹配

+0

它拋出編譯錯誤,因爲它很可能是你有分隔符,或不正確轉義的字符串。 – nhahtdh

+0

我有這個正則表達式,它看起來是否正確? 「^([A-Z0-9 + .-] +):(://(:((在[a-Z0-9 -._〜$&'()* +,=????!: ] |%[0-9A-F] {2})*)@)((?:?![A-Z0-9 -._〜$&'()* +,=] |%[O-圖9A-F] {2})*):* +,=(::(\ d *))(/([A-Z0-9 -._〜$&'(????!):@/] |%[0-9A-F] {2})*)|:* +,=?(/([A-Z0-9 -._〜$&'(?!):@] |% [0-9A-F] {2})+:;:|%[0-9A-F] {([* +,= @/A-Z0-9 -._〜$&'(!)〕 2})*))?(:\((:[* +; = A-Z0-9 -._〜$&'(!?:/ @????)] |%[0-9A-F ] {2})*))* +,=?(:#(([A-Z0-9 -._〜$&'(?!):/?@] |%[0-9A- F] {2})*))?」 – drwbns

+0

好吧,我發現這篇文章 - http://stackoverflow.com/questions/1252992/how-to-escape-a-string-for-use-in-boost-regex – drwbns

回答

0

有些事情,你可以從開始:

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;