Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript equivalent of PHP's preg_replace

I am using a simple regex to replace break tags with newlines:

br_regex = /<br>/; input_content = input_content.replace(br_regex, "\n"); 

This only replaces the first instance of a break tag, but I need to replace all. preg_match_all() would do the trick in PHP, but I'd like to know the JavaScript equivalent.

like image 259
ryonlife Avatar asked Jan 02 '09 16:01

ryonlife


1 Answers

Use the global flag, g:

foo.replace(/<br>/g,"\n") 
like image 185
annakata Avatar answered Sep 24 '22 21:09

annakata