[英]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? 有一个简单的C ++方法在字符串上使用模式匹配? The code should sound like this:
代码听起来像这样:
if (regexpcmp("l?nole*[0-9]", "linoleum1")) {
//we have a match!
} else {
//no match
}
Did you already look at Boost.Regex ? 你有没看过Boost.Regex ?
const boost::regex e("l?nole*[0-9]");
if (regex_match("linoleum1", e)) {
//we have a match!
} else {
//no match
}
Not in the core language. 不是核心语言。 Use Boost.Regex or an external library like
pcre
. 使用Boost.Regex或像
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. 在unix环境中,你几乎肯定可以访问BSD正则表达式工具(
regcomp
, regerror
, regexec
, regfree
),这些工具是c-like而不是c ++,但是可以工作。
如果您使用最常用编译器的最新版本,则可以在TR1名称空间中使用标准正则表达式库(基于boost :: regex):std :: tr1 :: regex。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.