String replacement via Regex

I’ve created some code which writes settings to a config file (for WordPress eg wp-config), and wraps this setting in comments.

Such as:

  # START WP_MEMORY_LIMIT
  define('WP_MEMORY_LIMIT', '250M');
  # END WP_MEMORY_LIMIT

But inorder to optimise my code I’m looking to drop the comments altogether and just directly write (and later delete) the setting via a regex. However, I’m not really sure where to start with this. So any help would be appreciated.

Essentially the regex would be able to idendify the following string of text in the config file:

  define('WP_MEMORY_LIMIT', 'xxxxxx');

Where ‘xxxxxx’ could be any alphanumerical value.

Read more here: String replacement via Regex

Leave a Reply

Your email address will not be published. Required fields are marked *