My <textarea>
contains a list of names with spaces between them, so I created a function to replace the spaces with new lines.
However, I now need to ensure that two or more spaces between names are considered part of the same element. For example:
John Lucas [[Laurie Vega]] [[Daniel Deer]] Robert
Should be transformed into:
John
Lucas
[[Laurie Vega]]
[[Daniel Deer]]
Robert
The regular expression
$("textarea").val().toString().replace(\ \g, '\n');
is not functioning correctly as it is adding new lines before "Vega" and "Deer."
I want to only replace spaces that are not between [
and ]
. I tried negating the expression, but it's not working:
// Works
$("textarea").val().toString().match(/\[([^\]]*)\]/g));
// Am I using the ! operand wrong?
$("textarea").val().toString().match(/!\[([^\]]*)\]/g));
I'm feeling a bit confused. I attempted to match and replace, but then I realized I wouldn't be able to retrieve the original string. Therefore, I have to find anything outside of double brackets and replace the spaces.