boost 之Regex

來源:互聯網
上載者:User

    最近做個小東西,用到了Regex,因為用的是C++,想趕下潮流,用下boost, 開始用boost::xpressvie, 在一台HP上一切都是正常的,然後到Sun的機器上進行編譯,發現居然編譯不過,暈倒了,還好及時到boost的網站上提交報告,不然自己瞎折騰,徒是浪費時間。 目前切換到 boost::regex 模組,但是遇到一問題,發現 如下Regex ((0|1)+,?)+ 在對於00101010 比較短時,沒有問題,在001010...串很長時,直接拋出一場,哥們就不知道怎麼回事了。而用boost::xpressive
則是不知道什麼時候能否解析完成。

家裡實驗的挺快的:

#include "boost/xpressive/xpressive_dynamic.hpp"
using namespace boost::xpressive;

void test_bitmap() {

  sregex reg = sregex::compile("((1|0)+,?)+");
  std::string datas[] = {
    "aaa-1&bbb-0&ccc-1",
    "1111000111",
    "11001010,101100100101010010101",
    "1001010010101100110010101010101001010,10101010",
    "100101001010110011001010101010100101010101010"};
  for (int i = 0; i < sizeof(datas) / sizeof(std::string); ++i) {
    std::cout << "match result:" << regex_match(datas[i], reg) << ", data:" << datas[i] << std::endl;
  }
}

int main() {
  cregex reg = cregex::compile("(\\s*\\d+\\s*|(\\[|\\()\\s*\\d+\\s*,\\s*\\d+\\s*(\\]|\\)))(\\s*,\\s*(\\s*\\d+\\s*|(\\[|\\()\\s*\\d+\\s*,\\s*\\d+\\s*(\\]|\\))))*");
  std::cout << regex_match("[ 10 ,100),1, 8", reg);

  test_bitmap();
  return 0;
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.