Regular expression induced the program can't respond

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ch2x

    Regular expression induced the program can't respond

    Now I have a regular expression:
    string pattern = @"[\s\S]*?(?<content>\< div
    id='news'\>\<di v[\s\S]*?\<\/div\>[\s\S]*?\<\/div\>)[\s\S]*";
    I want to use this pattern to match a html file's content,and replace the
    file's content with ${news}.
    But if the content is not match the pattern ,the program will lose response.
    Why ? and what shall I do?





  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Regular expression induced the program can't respond

    ch2x,

    What do you mean the program will lose response? It's possible that the
    regex engine is taking a long time to actually process this expression, and
    since you do it in the main thread of a windows forms application, that is
    why your app hangs.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "ch2x" <ch2x@163.com > wrote in message
    news:eTq5wslaFH A.580@TK2MSFTNG P15.phx.gbl...[color=blue]
    > Now I have a regular expression:
    > string pattern = @"[\s\S]*?(?<content>\< div
    > id='news'\>\<di v[\s\S]*?\<\/div\>[\s\S]*?\<\/div\>)[\s\S]*";
    > I want to use this pattern to match a html file's content,and replace the
    > file's content with ${news}.
    > But if the content is not match the pattern ,the program will lose
    > response.
    > Why ? and what shall I do?
    >
    >
    >
    >
    >[/color]


    Comment

    • ch2x

      #3
      Re: Regular expression induced the program can't respond

      Thanks for you reply.
      When the regex is not match the html file's content ,it is as what you said:
      regex engine will take a long time to actually proccess this expression.
      It is maybe the best way to resolve my matter,if there is a timeout event
      can be touched off.
      But regex engine doesn't have this event.and now what shall I do?



      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om>[color=blue]
      > ch2x,
      >
      > What do you mean the program will lose response? It's possible that[/color]
      the[color=blue]
      > regex engine is taking a long time to actually process this expression,[/color]
      and[color=blue]
      > since you do it in the main thread of a windows forms application, that is
      > why your app hangs.
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "ch2x" <ch2x@163.com > wrote in message
      > news:eTq5wslaFH A.580@TK2MSFTNG P15.phx.gbl...[color=green]
      > > Now I have a regular expression:
      > > string pattern = @"[\s\S]*?(?<content>\< div
      > > id='news'\>\<di v[\s\S]*?\<\/div\>[\s\S]*?\<\/div\>)[\s\S]*";
      > > I want to use this pattern to match a html file's content,and replace[/color][/color]
      the[color=blue][color=green]
      > > file's content with ${news}.
      > > But if the content is not match the pattern ,the program will lose
      > > response.
      > > Why ? and what shall I do?
      > >
      > >
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...