Skip to content

Regexp is being built without being properly escaped #9

@alanhogan

Description

@alanhogan

If you type special characters like [ (hard bracket) then regexps will fail.

This function will prevent this error:

function escapeRegExp(text) {
    return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}

Use it when you do text.search and when you call new RegExp() and you’ll be fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions