Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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
Javascript Jquery替换有前缀的单词_Javascript_Jquery - Fatal编程技术网

Javascript Jquery替换有前缀的单词

Javascript Jquery替换有前缀的单词,javascript,jquery,Javascript,Jquery,我想问一下在jquery中如何替换仅以$开头的单词,例如: //$example and $friend here means nothing just a regular string var txt = "This is just an $example my $friend"; 我想替换字符串中以$开头的所有单词,它们将在html标记中被替换,如下所示: This is just an <span class="php-var">$example</span> m

我想问一下在jquery中如何替换仅以
$
开头的单词,例如:

//$example and $friend here means nothing just a regular string
var txt = "This is just an $example my $friend";
我想替换字符串中以
$
开头的所有单词,它们将在html标记中被替换,如下所示:

This is just an <span class="php-var">$example</span> my <span class="php-var">$friend</span>
这只是一个$示例,我的$friend
我希望在客户端执行此操作,以便保存服务器性能,如下所示:

var txt = "This is just an $example my $friend";
var txt = txt.replace(/\$\S+/g,  '<span class="php-var">$&</span>');
var txt=“这只是一个$示例,我的$friend”;
var txt=txt.replace(/\$\S+/g,$&');
如下所示:

var txt = "This is just an $example my $friend";
var txt = txt.replace(/\$\S+/g,  '<span class="php-var">$&</span>');
var txt=“这只是一个$示例,我的$friend”;
var txt=txt.replace(/\$\S+/g,$&');
如下所示:

var txt = "This is just an $example my $friend";
var txt = txt.replace(/\$\S+/g,  '<span class="php-var">$&</span>');
var txt=“这只是一个$示例,我的$friend”;
var txt=txt.replace(/\$\S+/g,$&');
如下所示:

var txt = "This is just an $example my $friend";
var txt = txt.replace(/\$\S+/g,  '<span class="php-var">$&</span>');
var txt=“这只是一个$示例,我的$friend”;
var txt=txt.replace(/\$\S+/g,$&');

这不是一项繁重的任务。如果在服务器上执行,性能会有这么大的变化吗?我的意思是,这就是应该怎么做的
txt.replace(/\B\$\w+/g,“随便什么”)
做这个技巧这并不是一个很重的任务。如果在服务器上执行,性能会有这么大的变化吗?我的意思是,这就是应该怎么做的
txt.replace(/\B\$\w+/g,“随便什么”)
做这个技巧这并不是一个很重的任务。如果在服务器上执行,性能会有这么大的变化吗?我的意思是,这就是应该怎么做的
txt.replace(/\B\$\w+/g,“随便什么”)
做这个技巧这并不是一个很重的任务。如果在服务器上执行,性能会有这么大的变化吗?我的意思是,应该这样做
txt。replace(/\B\$\w+/g,“随便什么”)
起作用