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

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 have a match!
} else {
   //no match 
}

Answers


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.


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 
}

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.


Need Your Help

How do I populate a combo box with a column from my sql database

c# sql sql-server

How do I populate a combobox with a column from MySQL database?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.