Jump to content

Having Trouble With A Regular Expression In Replace


Greywacke

Recommended Posts

i need to replace all instances of "<br />" with \n, yet it only replaces the first if i do it as follows:

str.replace("<br />","\n");

i have tried googling for a solution, but all the answers were replacing "\n" with "<br />" as regular expressions (/\n//g with "<br />"), this has already been done.i've tried making the search for a regular expression as follows:

str.replace(/<br />/g/,/\n/);

and even with the / literal escaped, as well as the /g (otherwise i get undefined for g).:

str.replace(/<br \/>/g/,/\n/);

str.replace(/<br \/>\/g/,/\n/);

even with the \n as a string:

str.replace(/<br />/g/,"\n");

but to no avail... someone please help! i know after 10 years of javascripting and reading through manuals, i still don't quite get regular expressions.

Link to comment
Share on other sites

nevermind, i managed to get the regular expression right :)

str.replace(/<br \/>/g,"\n");

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...