regexp-replace

v1.0.2
base on RegExp#exec instead of String#replace
util regexp-replace regexp replace

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

npm i regexp-replace

Metadata

  • MIT
  • Whatever
  • SonOfMagic
  • released 2/21/2022

Downloads

Maintainers