Store regex expression in WordPress DB using Options API

I have been searching all afternoon for a solution and couldn’t find one. I am writing a plugin which needs to store regex expressions in the WP DB. An example expression is the following.

/(http:\/\/)(.*?)(example.com)/i

Storing the expression seems to work fine with update_option() and the entry in the database has the backslashes escaped with another backslash. However, when retrieving the option using get_option() the escape backslashes aren’t removed, and I need to apply stripslashes() to get rid of them.

Is this a reliable method to manage the storage and retrieval of backslashes in the WP DB? Are they missing a stripslashes() or similar when the get_option() is used to retrieve the expression from the database?

Solutions Collecting From Web of "Store regex expression in WordPress DB using Options API"

WordPress by default “escapes” all slashes and quotes in all input (historical reason, relic of the time PHP could have been configured to do it by default, or not). If you are handling forms by yourself instead of using the APIs you will need to strip the slashes, probably best to be done when saving the data.