JSPM

disable-regexp-capture

0.0.5
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 189
  • Score
    100M100P100Q95288F
  • License MIT

convert group to non-capturing-group: `(.+)` -> `(?:.+)`

Package Exports

  • disable-regexp-capture

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (disable-regexp-capture) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

disable-regexp-capture

convert group to non-capturing group (.+) -> (?:.+)

CircleCI

Install

$ npm install disable-regexp-capture -save

Usage

import disableRegexpCapture from 'disable-regexp-capture'

const disabledPattern = disableRegexpCapture(/\[([^[\]]+)\]/)
console.log(disabledPattern)
// => /\[(?:[^[\]]+)\]/

Behavior of String.prototype.split with RegExp.

without capturing-group

'aaa [tag1] bbb [tag2] ccc'.split(/\[[^[\]]+\]/)
// => [ 'aaa ', ' bbb ', ' ccc' ]

with capturing-group

'aaa [tag1] bbb [tag2] ccc'.split(/\[([^[\]]+)\]/)
// => [ 'aaa ', 'tag1', ' bbb ', 'tag2', ' ccc' ]

'aaa [tag1] bbb [tag2] ccc'.split(/(\[[^[\]]+\])/)
// => [ 'aaa ', '[tag1]', ' bbb ', '[tag2]', ' ccc' ]

with nested capturing-group

'aaa [tag1] bbb [tag2] ccc'.split(/(\[([^[\]]+)\])/)
// => [ 'aaa ', '[tag1]', 'tag1', ' bbb ', '[tag2]', 'tag2', ' ccc' ]

non-capturing-group in capturing-group

'aaa [tag1] bbb [tag2] ccc'.split(/(\[(?:[^[\]]+)\])/)
// => [ 'aaa ', '[tag1]', ' bbb ', '[tag2]', ' ccc' ]