2

the string is = "Reg.asp?q=RG_Price=5000*8000,Activated=1"

and i want to replace "RG_Price=5000*8000" with that "Price BETWEEN 5000 AND 8000".

Is that possible with Regular Expressions in ASP ?

casperOne
  • 73,706
  • 19
  • 184
  • 253

2 Answers2

2

Sure (now with VBScript instead of C#):

Dim queryString, replacedString
Set regEx = New RegExp
regEx.Pattern = ".+RG_Price=(\d+)\*(\d+).*"

replacedString = regEx.Replace(queryString, "Price BETWEEN $1 AND $2")
brien
  • 4,400
  • 4
  • 30
  • 32
  • This is not working in ASP. Microsoft VBScript runtime error '800a01c2' Wrong number of arguments or invalid property assignment: 'regEx.replace' –  May 29 '09 at 06:39
  • But in VBScript, it should work the same way: the object is still a `RegExp`, you set the `Pattern` attribute the same way, and the `Replace()` method still takes two arguments, the original string and the value to substitute for the matched pattern. (Although in the example above, queryString hasn't yet been set; it would need to be set to the queryString you pulled off the URL farther up in the code.) – Dave DuPlantis Oct 30 '09 at 16:48
0

I would use this regular expression:

^[^?]*\?(?:[^&]*&)*q=RG_Price=(\d+)\*(\d+)

and replace the match with "Price BETWEEN $1 AND $2".

But I don’t know ASP.NET so I cannot give you a working example.

Gumbo
  • 643,351
  • 109
  • 780
  • 844