How can I apply multiple regular expressions to a single line?
For example, a user enters the following into a text area:
red bird
blue cat
black dog
and I want to replace each carriage return with a comma, and each space with an underscore, so the last line will look like red_bird, blue_cat, black_dog.
I tried the syntax options on the following lines:
function formatTextArea() {
var textString = document.getElementById('userinput').value;
var formatText = textString.replace(
new RegExp( "\\n", "g" ),",",
new RegExp( "\\s", "g"),"_");
alert(formatText);
}
Choy source
share