0

I need a regular expression that matches this text description:

"any sequence that is not an F (upper case only) followed by a run of 1 or more digits (0-9)".

This needs to go as input to Java's Scanner.useDelimiter().

Suppose the input line is this:

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.

The tokenizer class Scanner should then retrieve F8, F12, F25, F44, F1, F121 and F99 for me.

Alternately, does Java allow negating a given regex?

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
FreeBird
  • 691
  • 1
  • 8
  • 18

1 Answers1

3

Use Pattern and Matcher classes to fetch only the chars you want.

Matcher m = Pattern.compile("\\bF\\d+").matcher(s);
while(m.find()) {
System.out.println(m.group());
}
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274