Add RegExp Support to Shopify Scripts

Highlighted
Shopify Partner
37 4 4

Hi,

 

Adding the RegExp class to Shopify Scripts API would open up a lot of additional functionality in Shipping Script in particular that is currently either difficult or impossible to do with the existing API. For instance RegExp would allow for:

 

  • Testing if one or more address lines is a PO box. UPS won't deliver to a box.
  • Testing for SKUs in the cart that modify shipping rates. Some Item variants may require special shipping rates.
  • Using with shipping_rate.delete_if? it would be far easier to remove all Priority rates for instance.
  • Testing for postal codes that have a rural code 0 in the 2nd place.
  • Many other operations I'm sure in Shopify Script

Right now the only string tests I'm aware of are ==, starts_with? and ends_with? which makes for difficulty in correctly testing the first use case mentioned above. Instead of

 

Input.cart.address1 =~ /^(p\.*o\.*|box)/i || Input.cart.address2 =~ /^(p\.*o\.*|box)/i

I have to generate all  of the possible combinations of characters matching that RegExp (with something like https://github.com/teeshop/rexgen) and add them to an array to then test with .starts_with?. This is very hackey and could be easily resolved with assess to RexExp functionality builtin to the script API.

 

This would help solve the long standing PO box issue and other I'm sure as well. Please add RexExp to the list of available classes in the Shopify Script API. Thanks!

 

Cheers,

Brad

0 Likes