📜 ⬆️ ⬇️

Stop writing regular expressions. Use verbal expressions

Immediately make a reservation, if you are a professional in the use of regular expressions, then you'd better not read further to avoid ^ (. *) $

The github user jehna found an interesting method of avoiding the implementation of complex regular expressions in the traditional way.
Verbal expressions transform a complex and sometimes non-trivial path from logic to regular expression itself into an unobtrusive walk using a related set of functions.

The result, to put it mildly, is amazing. Here is a verbal expression from the README file of the repository for testing the correctness of the URL:
var tester = VerEx()
            .startOfLine()
            .then( "http" )
            .maybe( "s" )
            .then( "://" )
            .maybe( "www." )
            .anythingBut( " " )
            .endOfLine();


, , (, . .) .

— JS-, .

.

P. S. - , , , .

')

Source: https://habr.com/ru/post/189852/


All Articles