3 ms·
Please make sure to use the level of regex that is standard on your team and be very selective about going beyond that. Always over-document your regexes and a
by jollybean 5y ago
Please make sure to use the level of regex that is standard on your team and be very selective about going beyond that.
Always over-document your regexes and assume people only have very basic regex skills.
- brigandish 5y agoAnd use the whitespace "trick" (usually via a metacharacter). This: HEADER_PARAM = /\s*[\w.]+=(?:[\w.]+|"(?:[^"\\]|\\.)*")?\s*/ is not as useful as this: / \s* # Maybe whitespace at the beginning [\w.]+ # Header key = # Equals (yes:) (?: # Header value from here [\w.]+ # Just about anything | # or " # it could be wrapped in quotes (?: [^"\\] # Not quotes or backslashes | \\. # Sometimes escaped characters occur )* # Could even be an empty string " )? # Maybe they didn't supply a value \s* /x If you can use interpolation with your regexes you can extend this idea into (largely) self-documenting regexes.
- jollybean 5y agoYes, this should be the best practice.