从字符串中提取数字

用户名

我知道已经回答了它,但是我正在努力从给定的字符串中提取数字

internal-pdf://2586543536/Homan-2014-RNA tertiary structure analysis by.pd

我需要提取“ 2586543536”

我正在使用以下正则表达式,我确定这是不正确的。

Pattern p = Pattern.compile("internal-pdf://\\d+");
Matcher m = p.matcher(value);
System.out.println(m.group(1));
威克多·斯特里比尤

您需要包装\d+一个捕获组,然后运行matcherm.find()以查找部分匹配项:

String value = "internal-pdf://2586543536/Homan-2014-RNA tertiary structure analysis by.pd";
Pattern p = Pattern.compile("internal-pdf://(\\d+)");
Matcher m = p.matcher(value);
if (m.find()){
    System.out.println(m.group(1)); 
} 

参见Java演示

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章