Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
537 views
in Technique[技术] by (71.8m points)

Javascript 正则表达式 非获取匹配 的问题

现在我有这么一个字符串:

<span class="php_start">&lt;?php</span>
    //Demo 0-2
    <span class="php_var">$str</span>="Hello World";
    <span class="php_keyword">echo</span> <span class="php_var">$str</span>;
<span class="php_start">?&gt;</span>

我要匹配"Hello World",用javascript,应该怎么实现??
我在网上查到很多比如

(?<!pattern)

酱紫的正则表达式,在str.raplace()里面似乎用不了??

————————————————————————————————————————————————————————————————————————————
查了一下,javascript正则不支持反向预查!!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
var str='<span class="php_start">&lt;?php</span>
    <span class="php_var">$str</span>="Hello World";
    <span class="php_keyword">echo</span> <span class="php_var">$str</span>;
<span class="php_start">?&gt;</span>';

str=str.replace(/<span[^<]*?</span>[wW]{0,1}/g,'');
console.log(str)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...