How to avoid a metacharacter in a regular expression
Language: asp
This is a sample of my code:
str = "www.example.com/gotobuy.aspx?id=1234"
key_word = ".obuy."
Dim regEx
Set regEx = New RegExp
regEx.Pattern = key_word
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(str)
if matches.count > 0 then
new_string = str
For Each Match in Matches
new_string = replace(new_string,match.value,"")
Next
else
new_string = str
end if
response.write new_string
The answer will open:
www.example.com/goaspx?id=1234
I know (.) Is one of the metacharacters. But what if I want (.) Just (.), Not a single word. What should I do?
Thanks for the help!
a source to share
In addition to the screening of .
a \
lot of people like to use a character class only .
in it: [.]
they think it more aesthetically pleasing. You also don't run into the issue of multiple levels of escaping. Since \
you may need to use a lot of levels of screening, if your language version of the line is treated \
as a special character: "\\."
.
a source to share