0

I want to match non-space characters, so I defined flex file with JFlex:

%%

Value = [\S]+

%%

{Value}   { return MyTokens.Value; }
.         { return MyTokens.BadCharacter; }

Then I try the generated java code to analyse the string "abc", but I get:

BadCharacter(a)
BadCharacter(b)
BadCharacter(c)

If I change the declaration to :

Value = [a-z]+

Then I can get expected result:

Value(abc)

Why \S is not working? Isn't it mean "non-whitespace"?

Freewind
  • 193,756
  • 157
  • 432
  • 708
  • Seems like `\S` is indeed supported by jflex: http://jflex.de/manual.html... FYI, though that's probably not the source of your issue, the brackets are redundant. `\S` can (should be able to) be used alone. – Robin Apr 17 '14 at 14:47
  • I found the reason: the version of JFlex I used is `1.4`, which doesn't support `\s`, `\S`. See the changelog of . Thank you all the same! – Freewind Apr 17 '14 at 14:54

1 Answers1

1

\S should indeed match a non-whitespace codepoint.

From the manual:

hese meta characters are equivalent to the following:
\S \P{Whitespace}

Edit: I didn't see you already replied in a comment: \S was introduced in version 1.5.

rds
  • 26,253
  • 19
  • 107
  • 134