Alex Rivera | Logout

Regular expressions - Matching whitespace

Asked 2012-11-09T23:03:52.350
9

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
Edit
Report

1 Answer

-1

I'm not a specialist in flex, but have you should use /g and /m flags in your regular expression, to work with multiline srings.

answered 2012-11-09T23:07:37.197

Your Answer