简体   繁体   中英

Regex for getting javascript functions in C#.net

I use webBrowser.DocumentText to get the html code of a page. using Regex, i manage to get the script tag part.
< script type="text/javascript">functions here..< /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
or list them down like this
1. function funtion1() { code here; }
2. function funtion2() { code here; }

purpose of the program is to identify if there's a duplicate javascript functions between 2 pages.
Its for winForms and language is 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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