正则表达式提取字符之间的数字
Regex extract number between characters
我返回的字符串格式如下:
PR ER
89
>
可以使用\n(\d+)
从中提取数字,但有时它returns:
23 PR P 10000>
或者,它可能是这样的:
23
PR P
10000
>
在这些情况下,如何提取 PR
和 >
之间的数字 10000
?
java 如果你需要
String str = "23 PR P 10000>";
Pattern reg = Pattern.compile("(\d+)");
Matcher m = reg.matcher(str);
while (m.find()){
System.out.println("group : " + m. group() + " - start :" + m.start() + " - end :" + m.end());
}
这可能对你有用:
\d+(?=\s*>)
它会查找后跟任意数量的空格和“>”的任意数字序列
我可能会自己回答这个问题
\d+\n>
成功了!
谢谢大家
我返回的字符串格式如下:
PR ER
89
>
可以使用\n(\d+)
从中提取数字,但有时它returns:
23 PR P 10000>
或者,它可能是这样的:
23
PR P
10000
>
在这些情况下,如何提取 PR
和 >
之间的数字 10000
?
java 如果你需要
String str = "23 PR P 10000>";
Pattern reg = Pattern.compile("(\d+)");
Matcher m = reg.matcher(str);
while (m.find()){
System.out.println("group : " + m. group() + " - start :" + m.start() + " - end :" + m.end());
}
这可能对你有用:
\d+(?=\s*>)
它会查找后跟任意数量的空格和“>”的任意数字序列
我可能会自己回答这个问题
\d+\n>
成功了! 谢谢大家