我使用了这个 (?:#\d{7})
正则表达式来仅提取 '#'
之后的 7 位数字。
例如,我有类似 "#1234567890"
的字符串。使用上述模式后,我将在 '#'
之后得到 7 位数字。
现在的问题是:我有类似这样的字符串“Referenc number #1234567890”
其中“引用编号#”
已修复。
现在我正在寻找可以从上述字符串返回1234567
数字的正则表达式。
我有一个文件,其中包含上述字符串,还有其他可用数据。
最佳答案
你可以尝试这样的事情:
String ref_no = "Referenc number #123456789";
Pattern p = Pattern.compile("Referenc number #([0-9]{7})");
Matcher m = p.matcher(ref_no);
while (m.find())
{
System.out.println(m.group(1));
}
关于java - 用于查找数据的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33543322/