I have a table named orders with a column named comment in it.
I have a list of order ids, and I want to search through all the comment to see which order has referenced them.
So far I have worked out the regex part of the sql
Order.where('comment ~ \'\s\d{5}\' OR comment ~ \'^\d{5}\'')
.where("comment LIKE '%?%'", order_id)
But I can't seem to work out a way to make the query more flexible to find order_ids that have different length other than 5
Is it possible to make {5} more dynamic, to something like {#{order_id.to_s.length}}?
UPDATE Just ran into this post Using a boundary match would work even better for this case.
Order.where('comment ~ \'\y?\y\'', order_id)
Would do the trick.