C++/CLI 中的正则表达式用法

标签 regex visual-c++ c++-cli

String^ matchStr = "eu";
String^ tempHeader;

for (int i = 0; i < header.size(); i++)
{
    tempHeader = gcnew String(header[i].c_str());
    if (Regex::Match(tempHeader, matchStr, RegexOptions::IgnoreCase))
    {
        index = i;
    }
}

以上是我尝试用于正则表达式的代码,但无论如何,它进入“IF”循环,并设置 index = i。

最佳答案

这是因为调用返回一个Match对象,它不是NULL。您需要检查 Success 属性:

if (Regex::Match(tempHeader, matchStr, RegexOptions::IgnoreCase)->Success)
{
    index = i;
}

关于C++/CLI 中的正则表达式用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9130232/

相关文章:

c++ - 使用 Visual C++ 编译器 (msvc) 从 CLion 终端构建 C/C++ Maven NAR 项目 : Cannot deduce version number

c++ - 简单的 C++ GUI 工具包

c# - C++ CLI gcnew 未声明的标识符

.net - 如何使用 C++/CLI 调用重写的基类方法

java - 验证文本区域

java - 在 Elasticsearch 上使用正则表达式过滤器开始的正则表达式是什么?

python - 相当于 Ruby 中 Python 的 findall() 方法?

c++ - 奇怪的 boolean 值

c# - 在 C# 中使用 C++ CLI 模板类

java - 从字符串中提取变量值