简体   繁体   English

正则表达式,用于在C#.net中获取javascript函数

[英]Regex for getting javascript functions in C#.net

I use webBrowser.DocumentText to get the html code of a page. 我使用webBrowser.DocumentText获取页面的html代码。 using Regex, i manage to get the script tag part. 使用正则表达式,我设法获得脚本标签的一部分。
< script type="text/javascript">functions here..< /script> <script type =“ text / javascript”>此处具有功能.. </ script>

I need to get functions inside those tags. 我需要在这些标签内获取函数。 ex. 恩。

<script type="text/javascript">
 function function1 () { code here;}
 function function2 () { code here;} 
<br>
</script>

I need regex pattern to get the 2 functions 我需要正则表达式模式来获得2个功能
or list them down like this 或像这样列出他们
1. function funtion1() { code here; 1. function funtion1(){代码在这里; } }
2. function funtion2() { code here; 2. function funtion2(){代码在这里; } }

purpose of the program is to identify if there's a duplicate javascript functions between 2 pages. 该程序的目的是确定2页之间是否存在重复的javascript函数。
Its for winForms and language is C# 对于winForms和语言,它是C#

You can not do it in any general way with regexes alone (especially not with the .NET flavour), since JavaScript scopes can be nested arbitrarily deeply and the language is therefore irregular. 您不能单独使用正则表达式(特别是不能使用.NET风格)以任何常规方式进行操作,因为JavaScript作用域可以任意深度嵌套,因此该语言是不规则的。 If you need them for a few particular pages, you might be able to craft a regex that handles common cases, but not all. 如果您需要在某些特定页面上使用它们,则可以制作出处理常见情况(但不是全部)的正则表达式。

e = ".*?(function.+?{.*?}|\\z)";
repl = "\\1";

I believe that's it. 我相信就是这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM