0

I am using regular expressions for text processing. For few sample texts, the Regex takes long time to process, because of which whole procedure is getting delayed.

I want to set a timer for the regex, so that if the regex exceeds the timer, skip the text and proceed further.

Is it possible to set in python ?

Sayse
  • 42,633
  • 14
  • 77
  • 146
Bhimasen
  • 677
  • 3
  • 8
  • 19
  • 2
    Wouldn't it be better to try and address why the regex takes a long time?... What have you tried so far? – Sayse Aug 17 '16 at 06:18
  • Normally it is taking time whenever i have included .* type of expression. I have fixed as much possible. but in a large amount of text it is difficult to track every exception. so i want to give a time bound. – Bhimasen Aug 17 '16 at 06:21
  • It is not at all surprising that adding `.*` makes regex matching slower - the `.*` grabs the whole line/string and backtracks trying to accommodate text portions for the subpatterns after `.*`. The more there are subpatterns after `.*` the slower is the performance. Fix your regexps rather than setting any timeouts. – Wiktor Stribiżew Aug 17 '16 at 06:25
  • Is there a well-known non-backtracking regex library in Python? – Alyssa Haroldsen Aug 17 '16 at 06:30

0 Answers0