Page 1 of 1

regex in natural language (javascript)

Posted: 15 Jul 2020, 15:03
by guest3456
Super Expressive is a zero-dependency JavaScript library for building regular expressions in (almost) natural language

https://github.com/francisrstokes/super-expressive

The following example recognises and captures the value of a 16-bit hexadecmal number like 0xC0D3

Code: Select all

const SuperExpressive = require('super-expressive');

const myRegex = SuperExpressive()
  .startOfInput
  .optional.string('0x')
  .capture
    .exactly(4).anyOf
      .range('A', 'F')
      .range('a', 'f')
      .range('0', '9')
    .end()
  .end()
  .endOfInput
  .toRegex();

// Produces the following regular expression:
/^(?:0x)?([A-Fa-f0-9]{4})$/

Re: regex in natural language (javascript)

Posted: 16 Jul 2020, 02:55
by SOTE
Very interesting. Good find!

Re: regex in natural language (javascript)

Posted: 16 Jul 2020, 09:13
by burque505
Thank you for finding this and sharing it, @guest3456.
Regards,
burque505