Nihilist Postmodern Mistake

    clean-regexp
    DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/clean-regexp package

    1.0.0 • Public • Published

    clean-regexp Build Status

    Clean up regular expressions

    Install

    $ npm install clean-regexp
    

    Usage

    const cleanRegexp = require('clean-regexp');
     
    cleanRegexp('[0-9]');
    //=> '\\d'
     
    cleanRegexp('[^0-9]');
    //=> '\\D'
     
    cleanRegexp('[a-zA-Z0-9_]');
    //=> '\\w'
     
    cleanRegexp('[a-z0-9_]', 'i');
    //=> '\\w'
     
    cleanRegexp('[^a-zA-Z0-9_]');
    //=> '\\W'
     
    cleanRegexp('[^a-z0-9_]', 'i');
    //=> '\\W'
     
    cleanRegexp('[a-zA-Z\\d_]');
    //=> '\\w'
     
    cleanRegexp('[^a-zA-Z\\d_]');
    //=> '\\W'
     
    cleanRegexp('[0-9]+\\.[a-zA-Z0-9_]?');
    //=> '\\d+\\.\\w'

    API

    cleanRegexp(regexp, [flags])

    regexp

    Type: string

    Text of the regular expression.

    flags

    Type: string
    Default: ''

    Flags of the regular expression.

    License

    MIT © Sam Verschueren

    Install

    npm i clean-regexp

    DownloadsWeekly Downloads

    617,053

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • samverschueren