I have a program extracting some information from a lot of large html pages. I found that the last line (myRegex.Match(detailPage)
) takes most of the execution time. Is the regex pattern optimized?
const string strRegex = @"prepend-top.*?<h1[^>]*?>(?<name>.+?)\s*<a.*?
Create\ Date.*?<label>(?<create>.*?)</label>.*?
<a.*?id\s*=\s*""period_report"".*?href\s*=\s*""(?<url>.*?)""";
const RegexOptions myRegexOptions =
RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Compiled |
RegexOptions.IgnorePatternWhitespace;
var myRegex = new Regex(strRegex, myRegexOptions);
var m = myRegex.Match(detailPage);
The HTML code looks like (The html file size is about 30K, however, most of the the html is javascript code):
<div class="span-24 prepend-top">
<h1>XXX XXX XXXX
<a href="https://....">Back to Search Results</a></h1>
</div>
<div class="span-18">
<div class="top-content">
<script type="text/javascript">
.....
</script>
<div class="detailHeaderContainer">
<div class="leftBlock">
<div class="left staticlabel leftStaticlabelWidth inlineColumn">
<label>
Product Type:
</label>
</div>
<div class="left leftDynamiclabelWidth dynamiclabel">
<label>Type 2</label>
</div>
<div class="clear"></div>
<div class="left staticlabel leftStaticlabelWidth inlineColumn">
<label>
Create Date:
</label>
</div>
<div class="left leftDynamiclabelWidth dynamiclabel">
<label></label>
</div>