0

How do i completely remove the following strings from my wordpress posts using regex?

NOTE: THESE ARE TEXT STRINGS THAT GOT HARDCODED WHEN I REIMPORTED MY POSTS.

Below are 3 examples however there can be 100s.

Here is the criteria: string starts with: googletag.cmd.push

String ends with: "); });

examples:

 googletag.cmd.push(function() { googletag.display("div-gpt-ad-cBdL_cggQrHX7u2qnNrMtQ"); });

 googletag.cmd.push(function() { googletag.display("div-gpt-ad-y_rI3cXW4HPKVfyNbLcmjg"); });

 googletag.cmd.push(function() { googletag.display("div-gpt-ad-TOILczxQd6hUhdv1UN5ETA"); });
4
  • Are you trying to cheat google ads? Commented Oct 1, 2016 at 2:22
  • No i exported posts from my old site. Now when i export them back in somehow this tag was saved as text. I used wp-import and wp-export. Commented Oct 1, 2016 at 2:32
  • what tool are you using to do the regex replace? Commented Oct 1, 2016 at 2:35
  • I am planning on using wordpress plugin search regex (wordpress.org/plugins/search-regex). However the data is in a custom field, if there is a better way to remove it i'll try it. Commented Oct 1, 2016 at 2:39

1 Answer 1

1

The regex to match your above examples is as simple as this

googletag\.cmd\.push\(.*?\); }\);

Demo: https://regex101.com/r/CBVqIw/1

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.