0

hopefully someone can help me.

I'm new to regexp...

I'm creating a commerce website for a local florists. They offer free postage within the local area (postcodes CM11 and CM12), and i'm looking to create fixed prices for further distances up to a 15 mile radius (they don't deliver outside 15 miles).

Shipping quote 1

  • I've created a 'free postage' shipping quote with the regexp condition that the postcode should be CM11 or CM12:
  • cm1[1]|cm1[2]
  • That works as expected and shows the free shipping if the postcode starts with CM11 or CM12.

Shipping quote 2

  • I've created a 'local delivery' shipping quote with the conditions below (this shows all the postcodes within a 15 mile radius)
  • cm[1-5]|cm1[3-7]|cm99|ig[2-3]|ig[6-7]|me3|rm[1-9]|rm1[0-9]|rm20|ss0|ss1[1-7]|ss2|ss22|ss[4-9]|ss9[9]

The issue / question I have is how to hide the 'local delivery' option from appearing when the user enters a CM11 or CM12 postcode. They should only see free delivery or collect in store (not the third option of local delivery)

You can see on my site (if you add something the cart and follow the checkout process, experiment with the postcode and see the delivery options change) - http://techyhelp.uk/florist/catalog/5

  • Sorry, the rules that worked are as above. If postcode is CM11 CM12 (In Billericay) show free post: cm1[1]|cm1[2] If postcode is any of these other ones (Within 15 miles of Billericay) show the local post option: cm[1-5]|cm1[3-7]|cm99|ig[2-3]|ig[6-7]|me3|rm[1-9]|rm1[0-9]|rm20|ss0|ss1[1-7]|ss2|ss22|ss[4-9]|ss9[9] I then tried adding a condition (and/or, i couldn't get either of them to work) saying something like: ^cm11|^cm12 Nothing I tried seems to work, i've yet to give the other commenters suggestion a go Thanks – user2685457 Jan 08 '17 at 17:10

2 Answers2

0

use a negative lookahead in your "local delivery" regex to filter out "cm12" and "cm11":

^(?!cm1[12]$)(cm[1-5]|cm1[3-7]|cm99|ig[2-3]|ig[6-7]|me3|rm[1-9]|rm1[0-9]|rm20|ss0|ss1[1-7]|ss2|ss22|ss[4-9]|ss99)$
Scott Weaver
  • 7,192
  • 2
  • 31
  • 43
0

sweaver2112 - that worked perfectly thank you.

So the answer to my question has been answered:

use a negative lookahead in your "local delivery" regex to filter out "cm12" and "cm11":

^(?!cm1[12]$)(cm[1-5]|cm1[3-7]|cm99|ig[2-3]|ig[6-7]|me3|rm[1-9]|rm1[0-9]|rm20|ss0|ss1[1-7]|ss2|ss22|ss[4-9]|ss99)$