javascript - how to get the <script> code use regular expression from the page source? -


i want script code ,except outer reference script . example: want code of :

<script type="text/javascript">alert("test");</script>  

from next s:

var s ='<script type="text/javascript" src="image/plupload/plupload.js"></script><script type="text/javascript" src="image/plupload/plupload.flash.js"></script><script type="text/javascript" src="image/plupload/plupload.html4.js"></script><script type="text/javascript" src="image/plupload/plupload.html5.js"></script><script type="text/javascript">alert("test");</script>'  p = /<(script)\s+((language=['"]?javascript['"]?)|(type=['"]?text\/javascript['"]?))?\s*\/?>.*(?:<\/\1>)?/gi; var arr = new array(); while(arr = p.exec(s))  alert(arr[1]+','+arr[1]+','+arr[2]); 

but regular expression wrong ,i can't right result

but parsing out non-nested script tags arbitrary string regular expressions , javascript easy:

var input = '<div>random html in here</div><script type="text/javascript" src="image/plupload/plupload.js"></script><script type="text/javascript" src="image/plupload/plupload.flash.js"></script><script type="text/javascript" src="image/plupload/plupload.html4.js"></script><script type="text/javascript" src="image/plupload/plupload.html5.js"><div>random html in here</div></script><script type="text/javascript">alert("test");</script><div>random html in here</div>'; var pattern = /<script[^>]+?>.*?<\/script>/gi; //whole thing. var matches = input.match(pattern); var result = ""; (var in matches) result += "match:" + matches[i] + "\n"; alert(result); 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -