Reputation: 19414
I should really be able to read a regexp by now, but all the same can anyone talk me through this?
/([^"^\s]+)\s*|"([^"]+)"\s*/g
Just for background; it's used in Alfresco to match on document tags. Is there a website out there you can plug these into and get an explanation back (other than SO)!
Upvotes: 0
Views: 711
Reputation: 4852
( # start a capture group
[^"^\s]+ # one or more characters NOT quote, caret, or white space
) # close capture group
\s* # followed by optional white space
| # either match everything before this '|' or everything after it
" # match a quote character
( # start capture group
[^"]+ # one or more characters NOT quote
) # close capture group
" # the closing quote
\s* # followed by optional white space
So as Blindy said, it either matches a string that doesn't have '^', quotes, or whitespace, OR, it matches everything between two quote characters. And it saves what it found in a backreference (what I've called 'groups' because I have Python stuck in my head).
Upvotes: 6
Reputation: 67447
It either matches an identifier (something that doesn't contain "
, ^
, or any space-like character -- space, tab, new lines) or something between quotes, either followed by any number of spaces.
Upvotes: 2