如何使用正则表达式查找特殊字符串之间的所有数字
How to use regular expression to find all numbers between special strings?
给定字符串:HelloWorld{12:777}ByeWorld{13:888}OkayWorld{14:999}
我希望的输出是:
12
13
14
如何写一个模式(在c++或Java中)找到字符串"World{"answers":"之间的所有数字?
使用查找或捕获组
Pattern.compile("(?<=World\{)[^:]*(?=:)");
或
Pattern.compile("\bWorld\{([^:]*):");
你可以试试:
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int main(void)
{
char ch[100];
scanf("%s", ch);
char *token;
token = strtok(ch, "{");
token = strtok(NULL, ":");
cout<< token << endl;
return 0;
}
相关文章:
- 在数字之间插入 + 或 - 符号以使其等于整数
- 将向量之间的数字放在另一个向量之间<vector>>如果两个数字的差值为 1
- 获取 2 个数字之间的差异百分比
- 两个有符号数字之间的距离
- 无法理解代码背后的逻辑,这是在两个给定数字之间生成素数的优化问题
- C++:这两种将数字写入矩阵的方式之间是否存在显着的速度差异?
- 如何从txt文件c++中提取括号之间的数字
- 正则表达式匹配字符串之间的数字
- C++显示两个区间之间的数字的程序检查一个数字是否可以表示为两个素数的总和
- 数字之间的比较
- 在没有比较运算符的情况下查找 2 个数字之间的最小值
- 在[a,b]间隔之间找到相同的数字
- 不理解连续数字之间的空格代码
- 如果 2 个数字之间的差值在 1 到 100 之间,则应运行 if 语句
- 第一个和第二个数字之间能被 4 和 6 整除的所有整数的总和
- 0 和 n 之间有多少个数字满足按位属性 i&y==i?
- 2 个给定数字之间的双精度密度
- 三个数字之间的 C++ 相加两个更高的数字,没有循环和数组
- 我如何生成2D数组,在行和列之间具有不同的数字
- 给定n个数字,编写一个例程,以在4个连续数字之间找到最大的数字