【发布时间】:2015-08-19 12:08:26
【问题描述】:
我需要一个匹配此文本描述的正则表达式:
"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 是否允许否定给定的正则表达式?
【问题讨论】:
-
与逆向拆分相比,匹配表达式本身通常更容易,例如
F\d+ -
@tobias_k 确实如此。请参阅下面 Avinash Raj 的答案。
标签: java regex regex-negation