I've got a <textarea>
that will be basically a list of names, so I set a function to replace the spaces between the names for a new line.
Now I need to specify that two or more spaces between names are in fact part of the same element.
IE:
John Lucas [[Laurie Vega]] [[Daniel Deer]] Robert
Should turn to
John
Lucas
[[Laurie Vega]]
[[Daniel Deer]]
Robert
So now my regexp $("textarea").val().toString().replace(\ \g, '\n');
is broken as it will add a new line before Vega and Deer.
I need to replace anything that's not in between [
and ]
. I just made the opposite and tried to negate it, but it doesn't seem to work:
// Works
$("textarea").val().toString().match(/\[([^\]]*)\]/g));
// Am I using the ! operand wrong?
$("textarea").val().toString().match(/!\[([^\]]*)\]/g));
I'm a little lost. I tried matching and then replacing, but that way I won't be able to recover my original string. So I have to match anything outside double brackets and replace the space.