Timeline for Regex to parse semicolon-delimited fields is too slow
Current License: CC BY-SA 3.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 14, 2013 at 16:02 | comment | added | Mike | Your solution is close, but if you look closer at my first attempt (that awful slow one), you will see, I tried to match the entry in the last field. Your last solution would have to look only for the last filed, e.g. line.split(";")[5] (if I counted right). It's a nice solution, thanks! | |
Nov 14, 2013 at 15:54 | comment | added | Mike | Hallo Alexander, ...file with just 3500 lines... ...want to grab every line from the filecontent that matches a certain string... This means: the file has 3500 lines in it. I refer to these 3500 lines as filecontent, as it is the content of the file... The phrase 'every line' wouldn't make sense, if we were talking about one-line files. | |
Nov 14, 2013 at 15:39 | history | edited | Alexander Torstling | CC BY-SA 3.0 |
added 335 characters in body
|
Nov 14, 2013 at 15:30 | comment | added | Alexander Torstling | @Mike: So "filecontent" actually signifies the content of one line in the file? | |
Nov 14, 2013 at 15:17 | comment | added | Mike | It wasn't in the example, but in the text before and after it ;) ...file with just 3500 lines... ...want to grab every line from the filecontent that matches a certain string... | |
Nov 13, 2013 at 14:46 | comment | added | Alexander Torstling | @Mike: Ok, but in your example I don't see any reference to newlines, did you mean that semicolon should signify newlines? Anyway, there is no "fast" way of splitting lines. The OS does not keep track of where newlines are stored, so scanning for newline chars is the way any row-reading lib works AFAIK. But you can of course save a lot of mem by reading line by line. | |
Nov 13, 2013 at 13:44 | comment | added | Mike | In my case it was about getting every full line (from some thousand lines) that has a certain string in it. Your solution gives back a part of the line, and would need some enhancements to work with some thousand files. I imagine you would suggest splitting by '\n' and then checking each line with 'if string in line' and putting that into a list then? Don't know if this would be faster. | |
Oct 9, 2013 at 18:36 | comment | added | Josh Anderson | Yup, +1 for split. Regex doesn't appear to be the best tool for this job. | |
Oct 9, 2013 at 16:17 | comment | added | kriss | +1: split is usually much faster than regex for these kind of cases. Especially if you need to use the captured field values aftwerward. | |
Oct 9, 2013 at 15:13 | review | First posts | |||
Oct 9, 2013 at 16:23 | |||||
Oct 9, 2013 at 15:04 | history | edited | Alexander Torstling | CC BY-SA 3.0 |
added filter step at end
|
Oct 9, 2013 at 14:56 | history | answered | Alexander Torstling | CC BY-SA 3.0 |