REGEXP_REPLACE in post_contet

So, basically, I want to remove trailing slashes from specific domain urls. For example: https://www.example.com/here/postname/ into https://www.example.com/here/postname

I have 10.4.21-MariaDB which should support REGEXP_REPLACE function.

This is my query:

UPDATE wp_posts SET post_content = REGEXP_REPLACE(post_content, '(http\S+)\/(\s|$)', '$1');

or this one more specifically:

UPDATE wp_posts SET post_content = REGEXP_REPLACE(post_content, '(https:\/\/www\.example\.com\/here\/\S+)\/(\s|$)', '$1');

which according to regular expressions should work: https://regex101.com/r/slLbgg/1

What am I doing wrong?

Any kind of help is appreciated! :)

This is the result:

Topic post-content regex Wordpress sql

Category Web


Ok, if someone in the future also needs something like this, I found the solution after some time of playing with regular expressions.

This worked for me:

UPDATE `wp_posts` SET `post_content` = REGEXP_REPLACE(`post_content`, 'https:\/\/www\.example\.com\/magazin\/(.*?)\/">', 'https://www.example.com/magazin/\\1">');

Example in action can be seen here: https://regex101.com/r/3ZPylJ/1

Hope it helps!

Smile to all :)

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.