本文介绍了下划线之间的正则表达式字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在下划线之间加上标记,例如:Com_x0020_este_x002C__x0020_texto
I need to get the markings between the underscores, for example:Com_x0020_este_x002C__x0020_texto
Com _x0020 _
este _x002C _
_x0020 _
texto
Com_x0020_
este_x002C_
_x0020_
texto
谢谢!
推荐答案
您正在寻找的preg_replace文档可在以下位置找到: http://php.net/manual/zh/function.preg-replace.php 以及您正在寻找的逻辑如下:
What you are looking for it preg_replace documentation can be found here: http://php.net/manual/en/function.preg-replace.php and the logic you are looking for it as follows:
$string = "Com_x0020_este_x002C__x0020_texto";
print preg_replace('/_(.*?)_/', " _$1_ ", $string);
Javascript版本:
var $string = "Com_x0020_este_x002C__x0020_texto";
alert($string.replace(/_(.*?)_/g," _$1_ "));
结果: Com _x0020_ este _x002C_ _x0020_ texto
这篇关于下划线之间的正则表达式字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!