any way to escape the expression when constructing a RegExp object?



Hi

We have some code that makes a RegExp object out of a variable:

var xxx = new RegExp(aString);

The problem is that sometimes the string contains regular expression
characters so the match isn't happening as we would like. For example
I want to match the literal string "[1-1]" but when this is the
variable that is made into a RegExp, I think it is interpreted as a
range because of the [] characters. Is there anyway I can tell the
constructor that I want to match [1-1]? I basically want to escape
any special characters: \[1-1\]

thanks for any help.
.



Relevant Pages

  • Re: Expert script (.bat) writers help needed (strip double-quote from string)
    ... Sets or returns the regular expression pattern being searched for. ... Always a RegExp object variable. ... May include any of the regular expression characters defined in the table in the Settings section. ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Finding a number in string - RegExp
    ... >the RegExp object? ... Does "number" mean digit, decimal digit, one or more of those, with a ... Does "by itself" mean that there must be no other characters in the ... string, no other "printing" characters?; or is it only the characters on ...
    (comp.lang.javascript)
  • Re: Modifying the regex pattern at runtime
    ... > You can use the RegExp object to create a regular expression from a ... > string. ... Michael, ...
    (comp.lang.javascript)
  • Re: Modifying the regex pattern at runtime
    ... You can use the RegExp object to create a regular expression from a ... string. ... Prev by Date: ...
    (comp.lang.javascript)
  • Re: Finding a number in string - RegExp
    ... the RegExp object? ... sign, with a decimal point, with an exponent part, octal or hexadecimal number, within the range of type Number ?? ... string, no other "printing" characters?; or is it only the characters on each side that matter?; what if it is at the beginning or end of the string? ...
    (comp.lang.javascript)