There is a function to use pattern matching (using regular expressions) in C++?

前端 未结 4 499
说谎
说谎 2020-12-21 15:02

There is a simple C++ method to use pattern matching on strings? The code should sound like this:

if (regexpcmp(\"l?nole*[0-9]\", \"linoleum1\")) {
  //we ha         


        
相关标签:
4条回答
  • 2020-12-21 15:32

    A standard regex library (that is based on boost::regex) is available in the TR1 namespace if you use lasts versions of the most used compilers : std::tr1::regex.

    0 讨论(0)
  • 2020-12-21 15:46

    Did you already look at Boost.Regex?

    const boost::regex e("l?nole*[0-9]");
    if (regex_match("linoleum1", e)) {
      //we have a match!
    } else {
      //no match 
    }
    
    0 讨论(0)
  • 2020-12-21 15:46

    Take boost.regex friend. if you are not allowed to use boost (sadly, there are still companies doing this), you could look into pcrecpp, which is a C++ binding developed by google for the famous PCRE library.

    0 讨论(0)
  • 2020-12-21 15:47

    Not in the core language. Use Boost.Regex or an external library like pcre. In a unix environment you almost certainly have access to the BSD regular expression tools (regcomp, regerror, regexec, regfree) which are c-like rather than c++-like but do work.

    0 讨论(0)
提交回复
热议问题