8 pontos por xguru 2020-07-22 | 2 comentários | Compartilhar no WhatsApp
  • Biblioteca JS que permite montar expressões regulares com funções compostas por palavras simples em inglês

Ex.) reconhecer código hexadecimal de 16 bits

→ /^(?:0x)?([A-Fa-f0-9]{4})$/

→ SE()

  .startOfInput

  .optional.string('0x')

  .capture

    .exactly(4).anyOf

      .range('A', 'F')

      .range('a', 'f')

      .range('0', '9')

    .end()

  .end()

  .endOfInput

  .toRegex();

2 comentários

 
iolothebard 2020-07-22

Nada muito natural...

 
kunggom 2020-07-22

É literalmente uma DSL.