c++ - 正则表达式可以与 C++ 中的字符数组一起使用吗

标签 c++ regex arrays char

我正在开发一个不能使用字符串库文件的程序,而是使用字符数组。我可以使用正则表达式,想知道是否有办法使用正则表达式和字符数组,甚至是正则表达式和单个字符?

我问的原因是当我尝试在匹配中使用我的 char 数组时,xUtility 从“TEMPLATE CLASS iterator_traits”中抛出一堆错误

if(regex_match(userCommand[3], userCommand[8], isNumeric))

错误:

Compiler error messages

最佳答案

std::regex_match及其 friend 通过迭代器工作(以及不仅是 const std::string& 的重载,还有 const char* 的重载)。

所以,是的,您绝对可以使用字符数组而不是 std::string。我建议阅读文档。


根据您的修改:

if(regex_match(userCommand[3], userCommand[8], isNumeric))

如果 userCommand 是数组,那么您将传入两个 char,而不是指针(“迭代器”)。

尝试:

if(regex_match(&userCommand[3], &userCommand[8], isNumeric))

或:

if(regex_match(userCommand + 3, userCommand + 8, isNumeric))

关于c++ - 正则表达式可以与 C++ 中的字符数组一起使用吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21321324/

相关文章:

c++ - 在定义期间将 std::string 设置为 0 与将 std::string 设置为 0

c++ - valgrind 错误 "Invalid read of size 4"

python - 用于python中单词排除的正则表达式

法语电话号码的正则表达式

PHP array_push 一个数组到另一个数组

javascript - 从 javascript 返回一个数组

c++ - 如何在函数内部创建一个对象并将其返回给 main() 而无需析构函数在 C++ 中将其删除?

使用模式和匹配器的 Java 正则表达式

Java int[][] 数组 - 迭代和查找值

C++ 将字符串拆分为字符串数组