Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8694733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:51:17+00:00 2026-06-13T00:51:17+00:00

I have a problem using Regex, in ASP.NET website. I wanna get the counts

  • 0

I have a problem using Regex, in ASP.NET website. I wanna get the counts of two regexes from a website source, using a webclient to download the source.

I wanna get the counts of a regex, searching on tmz.com website.

Basicly I have a text file with keywords on every line. I put 2 artists, and it should go to each line, make a regex pattern like artist1+regex+keyword+regex+artist2. The ideea is to see how many counts (searches are found) with my keywords and the artists.

Here is the source code of my function.

 int counts = 0;
    string line = "";
    StreamReader read = new StreamReader(@"C:\words.txt");
    WebClient web = new WebClient();
    string content = web.DownloadString("http://www.tmz.com/search/news/" + artist1 + " " + artist2);
    while ((line = read.ReadLine()) != null)
    {

            string pattern = artist1 + "[a-zA-Z0-9\\s]{1,10}" + line + "[a-zA-Z0-9\\s]{1,10}" + artist2;
            MatchCollection matches = Regex.Matches(pattern, content);
            counts += matches.Count;
            string pattern2 = artist2 + "[a-zA-Z0-9\\s]{1,10}" + line + "[a-zA-Z0-9\\s]{1,10}" + artist1;
            MatchCollection matches1 = Regex.Matches(pattern2, content);
            counts += matches1.Count;
    }
    read.Close();
    return counts;

But I get this error:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

And the red line that I got (line with error is this one):
Line 54: MatchCollection matches = Regex.Matches(pattern, content);

Exact exception:

System.ArgumentException was unhandled by user code
  Message=parsing "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:meebo="http://www.meebo.com/" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://ogp.me/ns/fb#">
<head>
        <script type="text/javascript">var _sf_startpt=(new Date()).getTime()</script>
    <title>Search bowwow tyra - news - Page 1 | TMZ.com </title>
    <meta name="robots" content="all"/>
    <meta name="description" content="Celebrity Gossip and Entertainment News, Covering Celebrity News and Hollywood Rumors. Get All The Latest Gossip at TMZ - Thirty Mile Zone" />
    <meta name="generator" content="Crowd Fusion 2.0-enterprise" />
    <!-- Site Verification -->
    <meta name="google-site-verification" content="UUmtbUBf3djgPpCeLefe_PbFsOc6JGxfXmHzpjFLAEQ" />
    <meta name="verify-v1" content="Wtpd0N6FufoE2XqopQJoTjWV6Co/Mny9BTaswPJbPPA=" />
    <meta name="msvalidate.01" content="AFEB17971BCF30779AEA662782EF26F4" />
    <meta name="y_..." - Too many )'s.
  Source=System
  StackTrace:
       at System.Text.RegularExpressions.RegexParser.ScanRegex()
       at System.Text.RegularExpressions.RegexParser.Parse(String re, RegexOptions op)
       at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options, Boolean useCache)
       at System.Text.RegularExpressions.Regex.Matches(String input, String pattern)
       at _Default.tmz(String artist1, String artist2) in c:\Users\icebox19\Documents\Visual Studio 2010\WebSites\WebSite3\Default.aspx.cs:line 52
       at _Default.Button1_Click(Object sender, EventArgs e) in c:\Users\icebox19\Documents\Visual Studio 2010\WebSites\WebSite3\Default.aspx.cs:line 89
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:

PS: I use ASP.NET website, not c# standalone application, this is a webpage.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:51:18+00:00Added an answer on June 13, 2026 at 12:51 am

    it is because you use the wrong parameters. it should be Regex.Matches(INPUT, PATTERN).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm using regex to get some information from a website, i have this code:
I have problem while using jquery maskedinput with asp.net textbox. I have a check
i have problem using LIKE structure in DB2 : for example: select * from
I have a problem using the SSIS. I try to import data from database
I have problem with one of my validation regex when using nonstandard utf-8 character.
I am using DataAnnotationsExtensions from http://dataannotationsextensions.org/ with an example from here http://weblogs.asp.net/srkirkland/archive/2011/02/23/introducing-data-annotations-extensions.aspx Controller Code
I'm trying to get strings inside a quote. I'm using regex but i have
I have problem need to solved with Regex If i am using Firefox or
I have a problem with validating an email address. I am using a RegEx
I am having a problem extracting a substring from a string using regex. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.