如何使用JAVASCRIPT /正则表达式从字符串中查找脚本标记 [英] How to find script tag from string with JAVASCRIPT/ regular expression

查看:87
本文介绍了如何使用JAVASCRIPT /正则表达式从字符串中查找脚本标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我需要验证文本< script的传入字符串。



例如:字符串a =这是一个简单的< script>字符串;

现在我需要写一个正则表达式会告诉我,这个字符串是否包含< script>标签与否。



我最后写了类似的内容: < *?script。*?>



但挑战是,

传入字符串可能包含以下方式的脚本,



1.字符串a =这是一个简单的 < script> 字符串;

2.字符串a =这是一个简单的 < script> 字符串;

3.字符串a =这是一个简单的 < ; javascript>< / javascript> 字符串;

4.字符串a =这是一个简单的 < script type = text / javascript> 字符串;



因此正则表达式应该检查是否有<标签,然后它应该检查脚本



请建议。

Hi All,

I need to validate the incoming string for text "<script".

Eg: string a = "This is a simple <script> string";
Now I need to write a regular expression that will tell me, whether this string contains <script> tag or not.

I ended up writing something like: <*?script.*?>

But the challenge is,
Incoming string may contain script in following ways,

1. string a = "This is a simple <script> string";
2. string a = "This is a simple < script> string";
3. string a = "This is a simple<javascript></javascript> string";
4. string a = "This is a simple <script type=text/javascript> string";

Hence the regular expression should check for starting "<" tag and then it should check for "script"

Please suggest.

推荐答案

参考

http://stackoverflow.com/questions / 1441463 / how-to-get-regex-to-match-multiple-script-tags [ ^ ]


这篇关于如何使用JAVASCRIPT /正则表达式从字符串中查找脚本标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆