如何查找“< script>”使用JAVASCRIPT /正则表达式从字符串中标记 [英] How to find "<script>" tag from the string with JAVASCRIPT/ regular expression
本文介绍了如何查找“< script>”使用JAVASCRIPT /正则表达式从字符串中标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要验证文本< script
的传入字符串。
I need to validate the incoming string for text <script
.
string a = "This is a simple <script> string";
现在,我需要编写一个正则表达式来告诉我这个字符串是否包含< script>
是否标记。
Now, I need to write a regular expression that will tell me whether this string contains a <script>
tag or not.
我最终写了类似的内容:< *?脚本。*?>
I ended up writing something like: <* ?script.* ?>
但挑战是,
传入字符串可能包含以下方式的脚本,
But the challenge is, Incoming string may contain script in following ways,
string a = "This is a simple <script> string";
string a = "This is a simple < script> string";
string a = "This is a simple <javascript></javascript> string";
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
.
推荐答案
A否定角色类在这里派上用场。
A negated character class comes in handy here.
<[^>]*script
这篇关于如何查找“< script>”使用JAVASCRIPT /正则表达式从字符串中标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文