Skip to content

Regex Generation #9

Open
Open

Description

@adammcarth

I need to find a way to transform a string into regex.

For example, if someone sets a ends_with: { value: "?" } } validation on a question title, it will muck up the regex.

Activity

  1. mikecmpbll commented on Oct 7, 2014

    @mikecmpbll

    you'll need to escape the input, something like:

    function escapeRegExp(str) {
      return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
    }
  2. adammcarth commented on Oct 7, 2014

    @adammcarth
    OwnerAuthor

    Ahh.

    I would have thought that new RegExp(); had an option that automatically did this :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions