我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

JavaScript相当于PHP的preg_replace

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

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

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.

Use the global flag, g:

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

JS idiom for non-Regexp global replace:

input_content.split('<br>').join('
')

近期文章

  • 无法在Windows服务器上传图像
  • FPDF输出()保存带有html扩展名的文件
  • 这是一个使用交易的好例子吗?
  • 从字符串中提取用户名和消息?
  • password_verify不返回true / false
  • Codeigniter中的用户角色和权限
  • 什么是最好的PHP DOM 2阵列功能?
  • PCRE:使用PHP捕获可选模式
  • SQL在自连接构造中获取所有内容
  • 如何确保用户观看完整视频?
  • PHP Try Catch Exceptions如何工作
  • 是php json_encode和AJAX打破我的阵列?
  • 我该怎么做才能使mysql 100%达到最佳状态?
  • mysql(i)_real_escape_string,安全可靠吗?
  • 确保URL来自同一服务器[重复]
  • 未定义的索引错误。 这有什么不对吗? [关闭]
  • 如何使用php解析HTML和预格式化[关闭]
  • PHP - 编辑/删除文件中的特定行
  • 在Web应用程序中使用Zhu Ramanan代码
  • PHP mysql_query update总是返回true

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华