我需要一个与此文字说明匹配的正则表达式:
"any sequence that is not an F (upper case only) followed by a run of 1 or more digits (0-9)".
这需要作为Java的Scanner.useDelimiter()的输入。
假设输入行是:
F8 has pretty solid open source cred: in F12 he founded F25, he was the F44 of F1 and the F121, and he helped pave the way for F99.
然后,标记生成器类Scanner应该为我检索F8,F12,F25,F44,F1,F121和F99。
或者,Java是否允许否定给定的正则表达式?
答案 0 :(得分:3)
使用Pattern和Matcher类仅获取所需的字符。
Matcher m = Pattern.compile("\\bF\\d+").matcher(s);
while(m.find()) {
System.out.println(m.group());
}