Rory Primrose

Learn from my mistakes, you don't have time to make them yourself

View project on GitHub

Splitting up arguments with a regular expression

Posted on February 18, 2009

There have been several times when I have needed to process a string that contains a set of arguments. It always seems to be a lot of work splitting up arguments by using white space as a delimiter because you need to take into account white space that is surrounded by brackets.

Just for kicks, I tried to come up with a regular expression that would do just that. Here is the result.

[^\s"]*"[^"]*"[^\s"]*|[^\s"]+