zero-length string in RegExp
Quote:
> Here is an example of the string:
> http://localhost/xyz/search/?qry=text&sort_by=rank&so=adc
> Now, I would like to sort by order and I want to change the value of
sort_by
> to title or something else. I read the Request.QueryString collection to
get
> the HTTP query string.
> ' It returns everything that comes after the "?".
> strQry = Request.QueryString
> My idea was to specify something like this
> re.Pattern = "(?:|&)sort_by=(?=.*)(?:|&)"
> The "(?=.*)" part will match the value of the sort_by argument. Is this
the
> best way to do it and how can I specify the zero-length string in the
> pattern (the first expression of my "|" (Or) operator).
Personally I won't use version 5.5 specific functions yet (no problem in
.ASP though since you know the engine available), and would therefore
recommend a solution using the old capture expressions:
Function ReplaceText(sText, sRepl, sPat)
Dim regEx
Set regEx = New RegExp
regEx.Pattern = sPat
regEx.IgnoreCase = False
regEx.Global = True
ReplaceText = regEx.Replace(sText, sRepl)
End Function
Dim s
s = "http://localhost/xyz/search/?qry=text&sort_by=rank&so=adc"
s = ReplaceText(s, "&sort_by=title", "&sort_by=[^&]*")
s = ReplaceText(s, "&so=something", "&so=[^&]*")
MsgBox s
Best regards
Johnny Nielsen