3 ms·
I'm not at all convinced by this, I'm afraid. Regexes are intimidating at first, but when you get the hang of them they are a fabulously powerful tool that abso
by macavity23 14y ago
I'm not at all convinced by this, I'm afraid. Regexes are intimidating at first, but when you get the hang of them they are a fabulously powerful tool that absolutely every programmer should learn.
As for 'laziness', I don't buy that regexes take any longer to write than the linked method. The third example can be done (in python, but I'm sure the ruby equivalent is just as simple) with:
re.sub(r'from\s+(\w+)\s+(\w+)\s+to\s+(\w+)\s+(\w+)', r"{'from': '\1 \2', 'to':'\3 \4'}", "from 4th October to 10th October")
Which is only ten characters longer, requires no external dependencies and can be used with very little modification in (almost) every other language.
- philh 14y agoThat's harder to read, partly but not entirely because you need to count parens and cross reference, and returns a string rather than a dict.