API Documentation for JSVerbalExpressions.
View the Project on GitHub
VerbalExpressions/JSVerbalExpressions
VerEx
• VerbalExpression
oneOrMore
Match the previous stuff one or more times.
const integer = VerEx().digit().oneOrMore();
console.log(integer.exec('foo 12345')[0]); // => '12345'
multiple
Match the previous group any number of times.
const expr = VerEx().startOfLine().find(' ').multiple().endOfLine();
console.log(expr.test(' ')); // => true
Match something zero or more times.
Parameter | Expected type | Description |
---|---|---|
value |
String |
Item to match |
const expr = VerEx()
.find('what').multiple('?')
.endOfLine();
console.log(expr.test('what')); // => true
expr.lastIndex = 0;
console.log(expr.test('what???'));// => true
Match something greater than or equal to min
number of times.
Parameter | Expected type | Description |
---|---|---|
value |
String |
Item to match |
min |
Number |
Minimum number of times it should be present |
const expr = VerEx()
.find('hurray').then('!').multiple(1)
.endOfLine();
console.log(expr.test('hurray')); // => false
expr.lastIndex = 0;
console.log(expr.test('hurray!!')); // => true
Match something between min
and max
(inclusive) number of times.
Parameter | Expected type | Description |
---|---|---|
value |
String |
Item to match |
min |
Number |
Minimum number of times it should be present |
max |
Number |
Maximum number of times it should be present |
const expr = VerEx()
.find('h').then('i').multiple(1, 3)
.endOfLine();
console.log(expr.test('hiii')); // => true
expr.lastIndex = 0;
console.log(expr.test('hiiii')); // => false