![](/img/trans.png)
[英]Boost.Python C++ object reference in Python: unexpected behaviour
[英]boost::regexp unexpected behaviour
我有這個正則表達式:
(?:^|\\n)[ \\t]*(-(.|\\n)*?)(?=\\n[ \\t]*-|$)
我想用這個文字來使用它
-h --help Show this screen.
--version Show version.
--prefix=<path> Set the specified path as the prefix
for paths mentioned below (except ones
specified manually).
-c, --config=<cfg-file> Configuration file name
[default: <prefix>/etc/myprog/protocols.conf].
--script=<asl-file> Input script file which will be played.
If not specified then contents of the
<prefix>/etc/myprog/script.active will be taken.
找出每個選項及其描述。 使用來自GCC 5.3的<regex>
,這個表達式按預期工作,但是如果我包含<boost/regex.hpp>
(此時的最后一個版本),它匹配
--prefix=<path> Set the specified path as the prefix
但不是
--prefix=<path> Set the specified path as the prefix
for paths mentioned below (except ones
specified manually).
有什么想法嗎?
加:
我在http://www.regextester.com/測試了這個正則表達式 - 它也表現得如預期的那樣。
加:
我使用boost的regexp源構建了一個共享庫,而沒有對其進行任何更改。 我用makefile中的這一行完成了這個:
g++ -std=c++0x -I../../include -O3 -Wall -c -fmessage-length=0 -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
和
g++ -Wl,--no-undefined -shared -o "libregex.so" $(OBJS) $(USER_OBJS) $(LIBS)
也許我需要調整boost :: regex的Unicode選項?
boost使用Perl的語法,因此$
不僅匹配行尾,而且也匹配“恰好在新行之前”( 在此介紹)。 因此,將regex_constants::no_mod_m
添加到正則表達式的標志中解決了我的問題。
另一種方法是更改表達式如下:
(?:\\A|\\n)[ \\t]*(-.*?)(?=\\n[ \\t]*-|\\z)
甚至:
^[ \\t]*(-.*?)(?=\\n[ \\t]*-|\\z)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.