PHP的JavaScript中的preg_replace

时间:2016-02-04 06:31:24

标签: javascript php jquery

如何在Javascript中执行preg_replace?

我在PHP中执行以下操作,但希望将其移至Javascript。

<?php

$errors  = '::Could not sign you into your account! ';
$errors .= '::Email or password error! ';

$errors = preg_replace('#\::(.+?)(?![^::])#','<div>$1</div>',$errors);

echo ($errors);

?>

Fiddle

我尝试使用JavaScript做同样的事情,但它不会以某种方式工作。有关如何做到这一点的任何想法?

var theString = "::Could not sign you into your account! :: Email or Password Error! ";

theString = theString.replace('#\::(.+?)(?![^::])#/g','<div>$1</div>');

alert(theString);

JsFiddle

1 个答案:

答案 0 :(得分:3)

Javascript regexps主要不使用引号和SELECT * FROM ( SELECT COALESCE(ta.country, tb.country) as country, tc.region FROM tb FULL OUTER JOIN ( SELECT country, region FROM tablec ) tc ON tc.country = tb.country FULL OUTER JOIN ( SELECT country, region FROM tablea ) ta ON ta.country = tb.country ) WHERE country IS NOT NULL AND region IS NOT NULL

COALESCE

小提琴:https://jsfiddle.net/rhtfzmxd/