开发者

C# Regex on large file, partial completion or get percentage done

I was wondering if there was any way to get any statistics from a Regex object while it is looking for matches.

I have a really large text file (+800kb) that I'm matching a fairly complex regex and it takes 2-5 mins to complete on some of th开发者_如何学JAVAe files. Is there any way I can break the document down into smaller chunks? Or is there a way to get the percentage done so I can know about how much time I have left?

Thanks :)


Is there anyway for you to predict a superset that can define a chunk (guaranteed to not break a regular expression)? i.e, do you know of a separator within the file which will not be caught within your regex? if not, I think you might not be able to do that.


Does your regex need to be applied to the whole file as one string, or could you apply it a line at a time? That would let you give progress in a reasonably obvious way, although you'd need to read all the lines to start with of course in order to give the progress as a proportion rather than just "completed N lines".

I don't believe there's any way of asking an already-executing regex what its progress is.


You're running the regex on the entire file at once? If you are, then no. If you're running it line-by-line, just keep a counter of which line you're on, then every so often print out the line number.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜