A normative substitution tagged-template function (s// replacement for js).
npm install perls> A s///-alike search-and-replace/substitution tagged-template-string for JS.
Makes Search-and-replace regex, or substitutions, available in JS. Use handy `perlsfind this/replace with/g to do text substiution.
`vader/anakin/
var perls= require("perls")
var lukesDad= perls("vader") //=> "anakin"(:
var threeCheers= perls("huzzah") //=> "huzzah huzzah huzzah"`
In JavaScript, RegExp.prototype.exec is used to get results out of regexp groups. If just trying to do some text substitution, that means writing a fairly gnarly string to concattenate together some output literal, from that exec output. This library exists to bring a more convenient means of doing text substitution to JavaScript.
In other non-JS environments, there's a s/find this/replace with this/ substitution one can run-
| language | example |
| --- | --- |
| perl | $myFav =~ s/replace this/with this/ |:s/replace this/with this/g 10000
| vim | |
Find and replace*
`jschange this text/now a replacement/
perls("it's a good start. change this text.") //=> "it's a good stat. now a replacement"`
Use a capture group*
`jsfind (\w+)/$1 once, $2 twice/
perls("find this") //=> "this once, this twice"`
Use a named capture grou*
`more (:
perls("more obama") //=> "obama! obama! obama!"`
Run the substitution ./.examples or their ./.tests to see usage.
Perls is distributed on npm.
From inside the project you want to add perls to:
npm install --save perls
Shout to to these fabulous libraries for their assistance:
named-js-regexp` to power named group matching.