Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regexp is being built without being properly escaped #9

Open
alanhogan opened this issue Jan 21, 2011 · 0 comments
Open

Regexp is being built without being properly escaped #9

alanhogan opened this issue Jan 21, 2011 · 0 comments

Comments

@alanhogan
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant