superreg
v0.2.1
Published
Better RegExp support for Javascript
Downloads
9
Readme
SuperReg
Better RegExp support for Javascript
Usage
SuperReg extends from RegExp
. It adds a few extra methods.
const reg = new SuperReg(/^[a-z](\d+)/)
const matches = reg.exec('a123')
// matches === [ 'a123', '123' ]
Methods
static escape (str pattern) str
Escapes all special chars in a string to make it usable as a RegExp.
const pat = SuperReg.escape('Hello ${name}')
// pat === Hello \$\{name\}
map (arr pattern) obj
Maps an array of keys onto a regexp
const keys = [
'one', 'two', 'three'
]
const pattern = /(one)|(two)|(three)/
const res = new SuperReg(pattern).map(keys, 'Number three')
// res = { one: '', two: '', 'three: 'three' }