2013-03-18 61 views
0

如何在使用std::tr1::regex_search時獲得匹配的索引?從tr1獲取匹配的索引:: regex_search

// sequence of string sub-matches 
std::tr1::smatch result; 

if (!std::tr1::regex_search(text, result, pattern)) 
    return false; 

我只能得到來自std::tr1::smatch result變量的字符串,而不是匹配的索引。

回答

1

我錯過了它,因爲我搜索了一個index方法,但它作爲一種方法正確 - std::tr1::smatch::position()將給出匹配的索引。

+0

好吧,那根本沒有升級。 – 2013-03-18 16:48:40

+0

我發現該方法感謝這個答案 - http://stackoverflow.com/a/234277/492336。這是關於Boost,但是正則表達式在tr1中似乎是相同的。所以StackOverflow仍然有很多幫助。 – sashoalm 2013-03-18 16:51:31