我一直在使用 Boost::regex 和 Boost::regex_search 并发现当我运行 regex
\\<(\\w+\\-?\\w+)\\>
这些都像平常一样匹配
BitcoinicaHacker> Who wants free bitcoins courtesy of bitcoinica?
<grepix> who doesn't!
<BitcoinicaHacker> post your btc addr
<nanotube> i think bitcoinica wants free bitcoins courtesy of bitcoinica
但是这样的行也会匹配
--> peacekeep3r (~peacekeep@chello084114169104.2.15.vie.surfer.at) has joined #bitcoin
<-- Raccoon has quit (Changing host)
--> Raccoon (bismuth@unaffiliated/raccoon) has joined #bitcoin
这相当令人困惑,因为我特别要求它找到一个左尖括号,然后是可能有破折号的文本,然后是一个右尖括号。
更新 2:
感谢 Ωmega 帮助我找到最佳解决方案: <(\\w+(?:\\-\\w+)*)>
更新:
任何一个
<(\\w+\\-?\\w+)> or <([^-<>]+[^<>]*)> works for my purposes.
我忘了删除转义斜线。