- Notifications
You must be signed in to change notification settings - Fork13
JavaScript implementation of SRL.
License
SimpleRegex/SRL-JavaScript
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
JavaScript implementation ofSimple Regex 🎉🎉🎉
Because of the JavaScript regex engine, there is something different fromSimple Regex
- Support
asto assign capture name with CODE but not regex engine. - NOT support
if already had/if not already had - NO
first matchand NOall lazy, since in JavaScriptlazymeans non-greedy (matching the fewest possible characters).
npm install srl
Class SRL accepts a Simple Regex Language string as input, and return the builder for the query.
The builder can agenttest/exec method to the generated regex object. Or you can useget() to take the generated regex object.
constSRL=require('srl')constquery=newSRL('letter exactly 3 times')query.isMatching('aaa')// truequery.getMatch('aaa')// [ 'aaa', index: 0, input: 'aaa' ]query.digit().neverOrMore().mustEnd().get()// /[a-z]{3}[0-9]*$/g
Required Node 8.0+ for the ES6 support, Or you can useBabel to support Node below 6.0.
UsingWebpack andbabel-loader to pack it if want to use in browsers.
In SRL-JavaScript we applyg flag as default to follow theSimple Regex "standard", so we provide more API to use regex conveniently.
isMatching- Validate if the expression matches the given string.constquery=newSRL('starts with letter twice')query.isMatching(' aa')// falsequery.isMatching('bbb')// true
getMatch- Get first match of the given string, like runregex.execonce.constquery=newSRL('capture (letter twice) as word whitespace')query.getMatch('aa bb cc dd')// [ 'aa ', 'aa', index: 0, input: 'aa bb cc dd', word: 'aa' ]
getMatches- Get all matches of the given string, like a loop to runregex.exec.constquery=newSRL('capture (letter twice) as word whitespace')query.getMatches('aa bb cc dd')/** * [ * [ 'aa ', 'aa', index: 0, input: 'aa bb cc dd', word: 'aa' ], * [ 'bb ', 'bb', index: 3, input: 'aa bb cc dd', word: 'bb' ], * [ 'cc ', 'cc', index: 6, input: 'aa bb cc dd', word: 'cc' ] * ] */
removeModifier- Remove specific flag.constquery=newSRL('capture (letter twice) as word whitespace')query.removeModifier('g')query.get()// /([a-z]{2})\s/
First, clone repo and init submodule for test.
SRL-JavaScript depends onMocha andIstanbul to test code. You can use them like this:
npm installnpmtest# testnpm run coverage# Get coverage locally
How to write Rules, see:Test-Rules.
SRL-JavaScript is published under the MIT license. See LICENSE for more information.
About
JavaScript implementation of SRL.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.