I am having a big problem to write a regexp that will trim all the whitespace in my input.
I have tried \s+ and [ \t\t\r]+ but that don’t work.
I need this because I am writing a scanner using flex, and I am stuck at matching whitespace.
The whitespace should just be matched and not removed.
Example input:
program
3.3 5 7
{ comment }
string
panic: cant happen
flexuses (approximately) the POSIX “Extended Regular Expression” syntax —\sdoesn’t work, because it’s a Perl extension.Is
[ \t\t\r]+a typo? I think you’ll want a\nin there.Something like
[ \n\t\r]+certainly should work. For example, this lexer (which I’ve saved aslexer.l):…successfully matches the whitespace in your example input (which I’ve saved as
input.txt):