how i can cancel a regex.ismatch() when it's working

Regex re = new Regex(text, RegexOptions.IgnoreCase);
if (re.IsMatch(text)) //it will be working for long time if the regex is not very right

.....

i can't have a timeout property for the regex member,so how i can solve this




Answer this question

how i can cancel a regex.ismatch() when it's working

  • mendraz

    I am not sure and maybe it is a silly answer but try to do it in thread. So you can suspend it
  • bonskijr

    You can use Timer object. And if Tick events you initiat your Regex object. If your Regex method doesn't reply within a certain time period you can dispose the timer. Which will eventually dispose ur regex object.

  • LucVK

    i know,but the cpu will tie up by the thread if just suspended it ,this will effect the next work

  • mikeroberts23

    FYI: I taken the opportunity to post a Microsoft Connect Suggestion Issue entitled Regular Expression (Regex) Improvements - Timeout & Pattern Tester which suggests that the Regular Expression be modified as following:

    1) Asynchronous operations available just as a web service to allow a user to run known regex'es in such a fashion.

    1.a) Ability to cancel a regex.

    2) Ability to specify a timeout on a match operation.

    3) Preprocess pattern evaluator to indicate if a regex pattern has identified regex pattern no-no's which could cause a regex match to not return or is malformed, such as missing a closing group parenthesis item such as (\d

    Maybe some of these could help your situation if implemented. Check out the connect item and vote on it if you feel it answers to your situation.


  • graphicsxp_too

    I know this doesn't answer the question, but it might be that the regex, for lack of a better term, is malformed and leads the processor into long processing times or a loop....

    Could you give us the regex and example text on what it is supposed to look for



  • how i can cancel a regex.ismatch() when it's working