开发者

Remove something in a match

I have this regex. My problem is the two second lines of the code:

<% 
content = ""+Request.Form("completehtml")+"";
contentmatch = content;
contentmatch = content.match(/<div class="content">[\s\S]+?#-#/ig); 
htstring1 = contentmatch;
htstring2 = htstring1.replace(/#-#/ig, '');
 %>

I want to match something and then after everything is matched, remove the #-# 开发者_如何学编程within the match

Is this possible?

I have found this to work:

contentmatch.match(/(<div class="content">[\s\S]+?)(?=[##])/ig);

But I still want to know how to use match and then replace within the math?

Anybody ?


Yes, its possible, and doable, but you should be able to do it in one step with groupings:

/(<div class="content">[\s\S]+?)#-#/ig

and then grab the group (enclosed via the parenthases), which will skip your need for the second regex.

(Every language allows you to reference groupings in a different way, and you dont' specify a language, so i didn't provide an explicit example of referencing the group.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜