How to Replace Value of CKEditor Field via Custom Module Drupal 8.x

I have a custom module and I am trying to wrap any string beginning with a hash tag in an 'a' tag via RegEx.

MYMODULE.module:

function MYMODULE_preprocess_node(&amp;$variables) {

    if ($variables['elements']['#node']-&gt;get('field_name')-&gt;value != '') {

        kpr($variables['elements']['#node']-&gt;get('field_name')-&gt;value);     
        $variables['elements']['#node']-&gt;get('field_name')-&gt;value = $newValue;
        kpr($variables['elements']['#node']-&gt;get('field_name')-&gt;value);

    }

}


I've left the two kpr() statements which do show initial value, and the RegEx replaced value, correctly. However, the value of the CKEditor field is not being replaced. It appears my 'equals' operator has no effect.

How do I replace the value of the CKEditor with my updated value?

Referencing this Stackoverflow question: https://stackoverflow.com/questions/22040272/using-php-replace-regex-with-regex
I have had some success.

MYMODULE.module:

use Drupal\Core\Entity\EntityInterface;

function MYMODULE_node_presave(EntityInterface $entity) {
  if ($entity-&gt;hasField('field_name')) {
    $entity-&gt;get('field_name')-&gt;value = $newValue;
  }
}