3 ms·
Never parse a data file with regex or string functions. Always spend the small extra time to at least write a state machine.
by mianos 5y ago
Never parse a data file with regex or string functions. Always spend the small extra time to at least write a state machine.
- belkarx 5y agoCould you elaborate on how this might be done?
- wallscratch 5y agoWhy? Aren’t all regular expressions equivalent to some finite state machine?
- rockemsockem 5y agoNever is a strong word. If I have a data file that I'm not going to use very much I'm definitely going to write 10 lines of python using re.find and string.find to get what I want out of it. Unless you have some nice way to quickly create a state machine besides using regexes?
- mianos 5y agoOK, you are right, never say never. For a once off, experiment or code never going to prod that you are always going to babysit, a regex is a good solution for speed and size of code. The trouble with most simple regexes to solve this, is the state machine is often not closed. A regex is way better than strcmp, ltrim, rtrim, mid and friends all held together with gum and tape.