正则表达式匹配问题

泊客天涯 2014-04-29 06:36:23
我想匹配html中的script代码,文档中可能有多个script,我想取得期中含有特定内容的一个怎么办,如
<acript>代码1</script>dfsdsdfsddfdsfsd黄航
fsdfsadfs
hjfghfg
jhgfjhghj
换行
<script>
代码2
换行
指定内容
代码3
</script>
dsdsd换行
换行
换行
sdfsdsd
dfsd
换行
sdsfd
<script>
代码4
换行
指定内容
代码5
</script>
都有若干换行,我想要我想要加红色标记的那一对script标记中的内容,利用“指定内容”
...全文
411 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
泊客天涯 2014-05-06
  • 打赏
  • 举报
回复
等待高手指点,我现在的表达式提取的内容不是

			<script type="text/javascript"><!--
			google_ad_client = "ca-pub-1066447241658620";
			/* penti */
			google_ad_slot = "8877964768";
			google_ad_width = 336;
			google_ad_height = 280;
			//-->
			</script>
			<script type="text/javascript"
			src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
			</script>
,结尾没问题,可开头却是
 <script type="text/javascript"><!--
    google_ad_client = "ca-pub-1066447241658620";
    /* CNzaobao468x60, 创建于 09-4-30 */
    google_ad_slot = "7704979228";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
</div>                </div>
        </div>
        <div class="left_box">
                <div class="my_ser_title">我们提供的服务</div>
    <div  class="my_ser">
    <ul> 
      </ul> 
   </div>
                <div align="center">
    <script type="text/javascript"><!--
google_ad_client = "ca-pub-1066447241658620";
/* CNzaobao468x60, 创建于 09-4-30 */
google_ad_slot = "7704979228";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script>
</div>        </div>
    </div>
        <div class="right">
        <div class="right_box">
            <script type="text/javascript"><!--
            google_ad_client = "ca-pub-1066447241658620";
            /* penti */
            google_ad_slot = "8877964768";
            google_ad_width = 336;
            google_ad_height = 280;
            //-->
            </script>
            <script type="text/javascript"
            src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
            </script>
祥子爱游戏 2014-05-02
  • 打赏
  • 举报
回复
我理解的正则就是找到相同或者不相同的地方进行匹配。 好像不太好找。我的思路树下。 1你要找的代码没有中文字符 2用分组找
泊客天涯 2014-04-29
  • 打赏
  • 举报
回复
要从下面代码中匹配出

			<script type="text/javascript"><!--
			google_ad_client = "ca-pub-1066447241658620";
			/* penti */
			google_ad_slot = "8877964768";
			google_ad_width = 336;
			google_ad_height = 280;
			//-->
			</script>
			<script type="text/javascript"
			src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
			</script>
这段代码,我该怎么写正则表达式?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
				  
<link href="../style.css" rel="stylesheet" type="text/css" />
<link href="../sty.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="favicon.ico" />
</head>
<body> 
  </div>
	<style>
 
	</style>
<div class="main">
	<div class="left">
    	<div class="search"> 
		</ul>
			<div align="center">
	<script type="text/javascript"><!--
	google_ad_client = "ca-pub-1066447241658620";
	/* CNzaobao468x60, 创建于 09-4-30 */
	google_ad_slot = "7704979228";
	google_ad_width = 468;
	google_ad_height = 60;
	//-->
	</script>
	<script type="text/javascript"
	src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
	</script>
</div>     	   	</div>
	    </div>
	    <div class="left_box">
				<div class="my_ser_title">我们提供的服务</div>
	<div  class="my_ser">
	<ul> 
      </ul> 
   </div>
	        	<div align="center">
	<script type="text/javascript"><!--
google_ad_client = "ca-pub-1066447241658620";
/* CNzaobao468x60, 创建于 09-4-30 */
google_ad_slot = "7704979228";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script>
</div>	    </div>
	</div>
	    <div class="right">
    	<div class="right_box">
			<script type="text/javascript"><!--
			google_ad_client = "ca-pub-1066447241658620";
			/* penti */
			google_ad_slot = "8877964768";
			google_ad_width = 336;
			google_ad_height = 280;
			//-->
			</script>
			<script type="text/javascript"
			src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
			</script>
		</div>
        <div class="right_box"><!-- Baidu Button BEGIN --> 
    </ul>
		</div>
    </div>	<div id="foot">
	<span><p><a href="http://www.Mefancy.com" target="_blank">Word Counter</a> | <a href="http://www.ThinkCalculator.com" target="_blank">ThinkCalculator</a><script type="text/javascript"> 
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3Fcb095cfc72cf799617b332336ec1f073' type='text/javascript'%3E%3C/script%3E"));
</script>
</p></span>
</div>
</div>
</body>
</html>
  • 打赏
  • 举报
回复
var str='<script>代码2'+
'换行'+
'指定内容'+
'代码3<\/script>';

var key='指定内容';

var reg=new RegExp('<(script)>[^<>]*?'+key+'[^<>]*?<\/\\1>');

alert(str.match(reg)[0]);
内容概要:本文系统研究了构网型变流器的正负序阻抗解耦特性及其在弱电网环境下的稳定性表现,重点依托Matlab/Simulink仿真平台,构建了详细的阻抗数学模型,设计了解耦控制策略,并采用小信号扫频法进行频域辨识与稳定性验证。研究深入探讨了构网型变流器与传统跟网型逆变器在正负序阻抗特性上的本质差异,结合虚拟同步发电机(VSG)等先进控制技术,分析其在抑制宽频带振荡、削弱锁相环动态耦合等方面的优越性。文中不仅提供了完整的仿真模型与MATLAB代码实现,还整合了光伏、风电、储能、微电网等多类新能源系统的阻抗建模与稳定性分析资源,形成了一套面向新型电力系统稳定性的综合性技术资料体系,具有较强的科研复现与工程参考价值。; 适合人群:面向具备电力电子、电力系统自动化、新能源并网等专业背景的研究生、高校教师及工程技术人员,特别适用于从事阻抗建模、小干扰稳定性分析、宽频振荡机理研究以及撰写高水平学术论文的科研工作者。; 使用场景及目标:①掌握构网型变流器正负序阻抗建模与扫频辨识的仿真方法;②深入理解VSG等构网型控制在弱电网中提升稳定性的内在机理;③复现顶刊论文中的阻抗分析流程与稳定性判据应用;④利用提供的成熟模型与代码加速科研进程,支撑课题研究与学术成果产出。; 阅读建议:建议结合文中提供的Simulink模型与MATLAB代码,按照“理论建模—仿真搭建—扫频激励—频响提取—Nyquist判据分析”的完整流程进行实践操作,重点关注扫频信号的注入方式、频率范围设置及阻抗曲线的物理意义解读,并参考博士论文复现案例深化对复杂动态耦合问题的理解。

87,987

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧