不匹配给定序列的正则表达式



我需要一个匹配这个文本描述的正则表达式:

"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允许否定给定的正则表达式吗?

使用Pattern和Matcher类来获取你想要的字符。

Matcher m = Pattern.compile("\bF\d+").matcher(s);
while(m.find()) {
System.out.println(m.group());
}

最新更新