24 Matching Annotations
  1. May 2020
  2. Feb 2020
    1. A combinaison of split(), subString(), removePrefix(), removeSuffix() is usually enough.

      Sometimes the following functions are more than enough for your string matching problems

  3. Nov 2019
  4. Oct 2019
    1. Really useful page for generating regexes of ip ranges. Note they are missing some parenthesis in places though.

  5. Sep 2019
  6. Mar 2019
  7. 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

  8. Oct 2018
  9. Sep 2018
  10. 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
  11. Apr 2017
  12. 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.