Hey
I'm storing a shopping basket in a session string.
It looks, for instance, like this:
1-1_9-1_13-1
Which follows the format:
ID1-Quantity1_ID2-Quantity2_ID3-Quantity3 etc etc etc...
That make sense? Good. Right: I'm trying to write a "remove item" function that, passed an ID number, will do a regExp search & replace; replacing the ID-Quantity pair in question with an empty string.
This is what I have so far:
Now I assume that all that is wrong with this is my inexcusable excuse for a regular expression.
What I want it to match, obviously (
) is a string consisting of the ID number of the item to be removed (strID) followed by a hyphen followed by a numeric value of between 1 and 3 characters in length.
It doesn't.
Any solutions? Is it just my dodgy regExp or am I overlooking something in the code?
Thanks
I'm storing a shopping basket in a session string.
It looks, for instance, like this:
1-1_9-1_13-1
Which follows the format:
ID1-Quantity1_ID2-Quantity2_ID3-Quantity3 etc etc etc...
That make sense? Good. Right: I'm trying to write a "remove item" function that, passed an ID number, will do a regExp search & replace; replacing the ID-Quantity pair in question with an empty string.
This is what I have so far:
Code:
function ereg_replace(strOriginalString, strPattern, strReplacement, varIgnoreCase) dim objRegExp : set objRegExp = new RegExp with objRegExp .Pattern = strPattern .IgnoreCase = varIgnoreCase .Global = True end with ereg_replace = objRegExp.replace(strOriginalString, strReplacement) set objRegExp = nothing end function strID=request("itemID") strBasket = session("basket") strBasket = ereg_replace(strBasket,"("&strID&"-[0-9]{1,3})", "", TRUE) ' remove any unattended underscores strBasket=replace(strBasket,"__","_") if right(strBasket, 1)="_" then strBasket=left(strBasket, len(strBasket)-1) end if session("basket")=strBasket
Now I assume that all that is wrong with this is my inexcusable excuse for a regular expression.
What I want it to match, obviously (

It doesn't.
Any solutions? Is it just my dodgy regExp or am I overlooking something in the code?
Thanks

Comment