It's really unclear what you mean by "I want to create a variable that don't match this pattern"
. Since t2 is your match, it seems like you want t3 to be objects that don't match.
Because you're anchoring to the start of the string (^
), this is a really great place to use a negative lookahead with almost the identical regex. Literally, all I did was surround it with (?!
and )
and .*
at the end..
output1.value = input.value.match(/^(?! *\+ *("(?:[^"]*)"|(?:[a-zA-Z]\w*)) *(.*)).*$/gm).join("\r\n")
An alternative is to use replace()
like so, but I would believe match()
is the better option.
output2.value = input.value.replace(/(^ *\+ *("(?:[^"]*)"|(?:[a-zA-Z]\w*)) *(.*)$\s*)+/gm,"")
For both cases, I added the g
lobal and m
ultiline to easily test several lines at once. If you're only testing one, remove both the g
and the m
, otherwise it could cause bugs by incorrectly telling you a string passed or failed when it didn't.
Demo: JSFiddle