Neutron Polarization Manipulator
Have ideas to improve npm?Join in the discussion! »

perl-regexpTypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

PerlRegExp

perl regexp in javascript

install

npm i perl-regexp

Added x modifier, you can add spaces in regular expressions

const p = new PerlRegExp(" (?:- (\\w) ) ", "xig");

// or
// const p = new PerlRegExp(/ (?:- (\w) ) /, "xig");

const r = p.replace("color-red", "\\u$1");
expect(r).toBe("colorRed");

replace

const p = new PerlRegExp(" ([A-Z]) ", "xg");
const r = p.replace("colorRed", "-\\l$1");
expect(r).toBe("color-red");

const p = new PerlRegExp("(-)");
const r = p.replace("color-red", (match, g1) => {
  expect(g1).toBe("-");
  return "_";
});
expect(r).toBe("color_red");
  • "\u" convert the next letter to uppercase
  • "\U" will convert the following characters to uppercase, until \E
  • "\l" convert the next letter to lowercase
  • "\L" will convert the following characters to lowercase, until \E
  • "\Q" put it to the non-word characters between \E and escape with a backslash
  • "\E" ends the scope of action \L, \U, \Q starts

Install

npm i perl-regexp

DownloadsWeekly Downloads

4

Version

0.5.0

License

MIT

Unpacked Size

16.9 kB

Total Files

19

Last publish

Collaborators

  • avatar