views:

418

answers:

2

Hello

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 ?

+1  A: 

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
This is not working in ASP.Microsoft VBScript runtime error '800a01c2'Wrong number of arguments or invalid property assignment: 'regEx.replace'
Tassos
Ahhh, I just assumed ASP.NET, that's C# code.
brien
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
A: 

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