JSPM

regexp-replace

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q33969F
  • License MIT

base on RegExp#exec instead of String#replace

Package Exports

  • regexp-replace
  • regexp-replace/dist/index.es.js
  • regexp-replace/dist/index.js

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 (regexp-replace) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

regexp-replace

base on RegExp#exec instead of String#replace.

Usage

const case = '<view class="p-[20px] -mt-2 mb-[-20px]">test case</view>'
const regex = /(?:class|className)=(?:["']\W+\s*(?:\w+)\()?["']([^"]+)['"]/gim
// remove class
replace(case, regex, (match, arr, idx, lastIdx, str) => {
  return ''
})

// sign
function replace(str: string, pattern: RegExp, replacement: string | ((match: string, arr: RegExpExecArray, index: number, lastIndex: number, string: string) => string)): string;

// params
// match -> RegExp match string
// arr -> RegExpExecArray
// index -> RegExpExecArray#index
// lastIndex -> RegExp#lastIndex
// string -> orignal string

More Usages see here