gpt4 book ai didi

c - C的strtok函数支持正则表达式吗?

转载 作者:行者123 更新时间:2023-11-30 21:43:44 24 4
gpt4 key购买 nike

假设我必须解析一些可以具有不同分隔符的电话号码。

示例:01/555555 01/555-5555

我可以在 c 中使用 strtok() 并给出一个正则表达式作为包含所有不同可能分隔符的分隔符参数吗?

最佳答案

不,它不支持正则表达式。在询问之前先阅读文档。另一方面,这正是它的工作原理Read the documentation ,即您给它所有可能的分隔符。

在这里查看

#include <stdio.h>
#include <string.h>

int
main(void)
{
char example[] = "exa$mple@str#ing";
char *token;
char *pointer;
pointer = example;
token = strtok(pointer, "@#$");
if (token == NULL)
return -1;
do
{
fprintf(stdout, "%s\n", token);
pointer = NULL;
} while ((token = strtok(NULL, "@#$")) != NULL);

}

关于c - C的strtok函数支持正则表达式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34746283/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com