JavaScript相当于PHP的preg_replace [英] JavaScript equivalent of PHP's preg_replace

查看:114
本文介绍了JavaScript相当于PHP的preg_replace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用简单的正则表达式用换行符替换break标记:

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

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

这只替换了break标记的第一个实例,但我需要替换所有。 preg_match_all()可以用PHP来解决问题,但我想知道等效的JavaScript。

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.

推荐答案

使用全球标志, g

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

这篇关于JavaScript相当于PHP的preg_replace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆