Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP';JavaScript中的preg_替换_Javascript_Php_Jquery - Fatal编程技术网

PHP';JavaScript中的preg_替换

PHP';JavaScript中的preg_替换,javascript,php,jquery,Javascript,Php,Jquery,如何在Javascript中进行preg_替换 我在PHP中执行以下操作,但希望将其移动到Javascript <?php $errors = '::Could not sign you into your account! '; $errors .= '::Email or password error! '; $errors = preg_replace('#\::(.+?)(?![^::])#','<div>$1</div>',$errors); ec

如何在Javascript中进行preg_替换

我在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);

?>

我试着用JavaScript做同样的事情,但不知怎么的,它就是不起作用。关于如何做到这一点有什么想法吗

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

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

alert(theString);
var theString=“::无法将您登录到您的帐户!::电子邮件或密码错误!”;
字符串=字符串。替换(“#\::(.+?)(?![^::]))#/g',“$1”);
警报(字符串);

Javascript正则表达式大多不使用引号和

var theString=“::无法将您登录到您的帐户!::电子邮件或密码错误!”;
字符串=字符串。替换(/\:(.+?)(?![^::])/g,“$1”);
警报(字符串);

Fiddle:

Javascript正则表达式大多不使用引号和

var theString=“::无法将您登录到您的帐户!::电子邮件或密码错误!”;
字符串=字符串。替换(/\:(.+?)(?![^::])/g,“$1”);
警报(字符串);
Fiddle:

有一些有用的信息可以指导您有一些有用的信息可以指导您
var theString = "::Could not sign you into your account! :: Email or Password Error! ";
theString = theString.replace(/\::(.+?)(?![^::])/g,'<div>$1</div>');
alert(theString);