Skip to content

Instantly share code, notes, and snippets.

View lokshunhung's full-sized avatar
🐱

LS Hung lokshunhung

🐱
  • Hong Kong
View GitHub Profile
@lokshunhung
lokshunhung / JavaScript-RegExp.js
Created August 2, 2020 09:00
JavaScript: String.prototype.match & RegExp.prototype.exec
// A scratchpad testing the differences between:
// - `String.prototype.match` (with & without `g` flag)
// - `RegExp.prototype.exec` (with & without `g` flag)
const str = "A string\nWith 2 endlines\n";
(function () {
console.info("==== String.prototype.match GLOBAL ====");
const re = /(\w)(?<NamedGroup1>\w)\n/g;
// Returns an array containing **all** string segments matching the **whole regex**