regex in natural language (javascript)

Discuss other useful utilities, general computing tips & tricks, Internet resources, etc.
guest3456
Posts: 3134
Joined: 09 Oct 2013, 10:31

regex in natural language (javascript)

15 Jul 2020, 15:03

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})$/

SOTE
Posts: 1056
Joined: 15 Jun 2015, 06:21

Re: regex in natural language (javascript)

16 Jul 2020, 02:55

Very interesting. Good find!
burque505
Posts: 1353
Joined: 22 Jan 2017, 19:37

Re: regex in natural language (javascript)

16 Jul 2020, 09:13

Thank you for finding this and sharing it, @guest3456.
Regards,
burque505

Return to “Other Utilities & Resources”

Who is online

Users browsing this forum: No registered users and 8 guests