我需要一个与此文本描述匹配的正则表达式:
"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());
}
关于java - 与给定序列不匹配的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32095103/