Regex Match All Characters Except Space (Unless In Quotes)

Category: Strings

A regular expression to match all characters in a string except space (unless in quotes).

It is useful for developers to split a string into an array.

/\w+|"[\w\s]*"/

Matches:

  • Anything but space (unless in quotes)

See Also:

Rate This Regex
Sending
User Review
0 (0 votes)

Expression Flags

Flags Description
i Ignore case sensitive.
g Allows global search.
m Allows multiline search.