I have a pretty ugly text-processing question. I'm trying to match a string denoted as a boundary by MIME headers then use it as a variable to annotate the different sections of a multipart message. This would be fine, except for the fact that the boundary strings conatin lots of regular expression quantifiers and tend to look like
EB-002(.BhNa.RALxMe_ZRHLIBVcyn_4sgz+G(v
I tried backslashing the variable name for the boundary string like:
if (/^-+\$boundary/){<br>
but this never matched the following instances, although it did let me use the string without a bad regex error. Just for kicks, I also tried using a backslash on the input, since it has the same problematic characters, but it doesn't get evaluated as a regular expression, so that unsurprisingly had no effect.
My question then is "Is there a way to safely (and efectively) use strings that contain special regex characters as patterns to be matched, without knowing ahead of time when, where and which special characters will occur in the pattern?"
In reply to safe regex variables by oconnelm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |