Closed frmatthew closed 8 years ago
I was wondering about this too. How about (\([^)]+\)|\S)+
? Or maybe (\([^)]+(\)|$)|\S)+
so that it would still work when the final closing parenthesis hasn't been entered yet.
Not quite as easy to read as \S+
perhaps, but it ought to get the job done.
I was thinking of var words = gabcNotations.split(/\s+(?=[^\)]*(?:\(|$))/g);
(as opposed to trying to match tokens with spaces in them)...
I'm not sure there's much difference; it's funny to me because when I first looked at the code gabcNotations.match(/\S+/g)
, I thought, "that's interesting, because I would have thought that gabcNotations.split(/\s+/)
would be more clear. Funny how different things seem the intuitive way of doing the same thing. Also, I don't think the g tag on the regular expression will do anything if you are passing it into split().
However, in this case, there is more of a difference, but I'm still not sure the advantages and disadvantages of each.
Agreed, it's probably six of one, half dozen of the other.
Incidentally, I've always had this thought that it might be possible to create a single regex to process the gabc code all in one pass...but that would certainly be a rather unreadable regex.
Use a regex that splits words on spaces that are not between parentheses?