开发者

Boost regex_search for unstructured strings

Hello after going through the existing labels on this topic and haven't had found anything, I thought I will ask out here. Essentially I am a newbie to regex and C++ but am trying to port some legacy code to C++. Any help in terms of even literature to read is greatly appreciated.

I have a pattern string that searches for "Life\\s*Policy\\s*=\\s*(([0-9]+)|[0-9]+\\.[0-9]*);" in a string that is "Life Policy = 9.67; Life Benefits = 1000; Life Claim = 100"

How can I use the regex_search function to get the value 9.67 so that I can use it in my calculations further??

I have this code currently and I am unable to extract what I want:

std开发者_JAVA百科::string::const_iterator begin;
boost::match_results<std::string::const_iterator> what;
begin = st.begin();
boost::match_flag_type flags = boost::match_perl;

while(boost::regex_search(begin,st.end(),what,ex,flags))
{
    successcode = 200;
}

My idea was that what will have all the information that I need. but what[0].first points me to the beginning of the string that is matched...i.e Life Policy = 9.67;Life Claims = ..


what[0] matches the entire string. what[1] represents the first match, what[2] the second, and so on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜