tags:

views:

274

answers:

5

Language: asp

This is sample of my code:

str = "www.url.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 response will display:

www.url.com/goaspx?id=1234

I know (.) is one of Meta Character. But what if I want (.) just is (.), not any single word. What should I do?

Thanks for helping!

+2  A: 

Use \. to match a . literally.

Alex Martelli
+1  A: 

You need to escape the meta-characters that you want to be treated literally. In most regex systems this means prefixing it with a backslash. eg: "foo\.bar"

Laurence Gonsalves
+2  A: 

In addition to escaping the . with \, many people like to use a character class with only . in it: [.], they find it more aesthetically pleasing. You also don't run into the problem of multiple levels of escaping. With \, you may have to use many levels of escaping if your language's version of strings treat \ as a special character: "\\.".

Chas. Owens
+2  A: 

Since . is a metacharacter, to match '.' you need to escape it, like as \.

Nathaniel Flath
A: 

For a great regular expression tutorial see http://www.regular-expressions.info/

Tom Leys