Hacker News new | ask | show | jobs
by qaq 3022 days ago
for those who find regex not very readable: https://github.com/VerbalExpressions // Create an example of how to test for correctly formed URLs var tester = VerEx() .startOfLine() .then('http') .maybe('s') .then('://') .maybe('www.') .anythingBut(' ') .endOfLine();
1 comments

https://github.com/pygy/compose-regexp.js is another option (800 bytes mingzipped):

    const {sequence, suffix} = composeRegexp;
    const maybe = suffix("?");
    const oneOrMore = suffix("+");

    const urlMatcher = sequence(
      /^/,
      "http"
      maybe("s"),
      "://",
      maybe("www."),
      oneOrMore(/[^ ]/),
      /$/
    );