5 ms·
I agree, I find regular expressions to be the clearest way to describe families of strings that share a specified structure and no longer find them hard to read
by fiddlerwoaroof 4y ago
I agree, I find regular expressions to be the clearest way to describe families of strings that share a specified structure and no longer find them hard to read. This sort of argument has always struck me a bit like the way people will say “Greek is hard to read because you have to learn the alphabet”: learning the alphabet for Greek isn’t the hard part of learning Greek and, similarly, learning the meaning of the characters used in regexes isn’t the hard part of using regexes. The hard part is learning to think in the language that uses those characters.
- marginalia_nu 4y agoRegular expressions are virtually always easier to read because they're so much terser. I unroll a fair bit regular expressions because they are typically an order of magnitude slower, and it's almost never an upgrade in readability. Compare for example something trivial like [a-f0-9]{32} with its unrolled form public boolean hashTest(String path) { int runLength = 0; int minLength = 32; if (path.length() <= minLength + 2) return false; for (int i = 0; i < path.length(); i++) { int c = path.charAt(i); if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')) { runLength++; } else if (runLength >= minLength) { return true; } else { runLength = 0; } } return runLength >= minLength; }