Verbal-expressions

JavaScript Regular Expressions made easy

VerbalExpressions helps us to construct difficult regular expressions is an intuitive manner.

Install it: npm install verbal-expressions

Example usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
var ve = require('verbal-expressions');
var url = "http://nmotw.in";
var vre = ve()
  .startOfLine()
  .then( 'http' )
  .maybe( 's' )
  .then( '://' )
  .maybe( 'www.')
  .anythingBut( " " )
  .endOfLine();

vre.test(url); //true

vre.toRegExp(); // /^(?:http)(?:s)?(?:\:\/\/)(?:www\.)?(?:[^\ ]*)$/gm

What else do we have?

Modifiers:

  • anything()

  • anythingBut( value )

  • endOfLine()

  • find( value )

  • maybe( value )

  • startOfLine()

  • then( value )

Special characters and groups:

  • any( value )

  • anyOf( value )

  • br()

  • lineBreak()

  • range( from, to)

  • tab()

  • word()

Modifiers:

  • withAnyCase()

  • stopAtFirst()

  • searchOneLine()

Functions:

  • replace( source, value )

Others:

  • add( expression )

  • multiple( value )

  • or()

GIF FTW!

Thanks to Mihai Ionut Vilcu for verbal expressions!

Suggest a module

Comments