13 Matching Annotations
  1. Mar 2019
  2. Nov 2018
    1. /^10.\d{4,9}/[-._;()/:A-Z0-9]+$/i

      Actually, it'd be better to express this as /^10.\d{4,9}/[-._;()/:a-zA-Z0-9]+$i (adding lowercase letters a-z, instead of using the case insensitivity flag "i") to avoid compatibility issues with certain regex parsers

  3. Oct 2018
  4. Sep 2018
  5. Jun 2017
    1. It will then backtrack from the end until it reaches the first space.

      so greedy is evil? since it'll backtrack form the end!

    2. The faster you can throw out non-matching input, the fewer cycles you waste

      but in log analysis field, almost every line are machted, we'just want to use regex to extract fields inside the line. Is the "the longer the better" still matter?

    1. Character classes Possessive quantifiers (and atomic groups) Lazy quantifiers Anchors and boundaries Optimizing regex order
  6. Apr 2017
  7. Nov 2016
    1. Interesting dive into how string slicing with String#substring is implemented in the Dart and V8 VMs and the performance consequences of that. This investigation was prompted by poor performance of a port of less.js lexer to Dart vs. the original JS implementation.

      The article ends with benchmarks showing the cost of trying to match sequences of characters in a lexer using a regex vs. manually.

    2. A person with a bit more insight into RegExp features might come up with the following optimization:

      Neat trick for matching regular expressions within a string starting at a fixed position using pre-ES6 features:

      1. Create a regex with the global flag set which matches pattern|() where () is an irrefutable pattern which is guaranteed to match
      2. Set regex.lastIndex to the position you want to match at
      3. Use regex.exec(str)
    3. match can be easily implemented in any modern JavaScript interpreter that supports sticky RegExp flag introduced in ES6:

      Notes on how to match a regex starting at a given position in a string, making use of the sticky flag introduced in ES6.