<p>I'll add my two cents here, since it appears you are removing Wordpress created images (which I also did).</p>

<p>I wrote a regex initially to find all these duplicated files (this command works specifically on OSX, but is pretty portable):</p>

<pre><code>find -E . -regex '.*\-[0-9]{1,4}\x[0-9]{1,4}\.(png|gif|jpg)$'
</code></pre>

<p>I then wrote a minor change to delete them:</p>

<pre><code>find -E . -regex '.*\-[0-9]{1,4}\x[0-9]{1,4}\.(png|gif|jpg)$' -delete
</code></pre>

<p>I figure you can use this same regex pattern to find/replace in a database dump locally, which this answer here points to: <a href="https://stackoverflow.com/a/9456574/776167">https://stackoverflow.com/a/9456574/776167</a></p>

CC BY-SA 3.0
2017-12-19T14:11:39.280Z
2017-12-19T14:11:39.280Z
hisnameisjimmy
<p>Nope, because MySQL doesn't support RegEx replacements in SQL statements.  It's been an <a href="http://bugs.mysql.com/bug.php?id=27389" rel="nofollow">open feature request</a> since 2007, so feel free to add your vote.</p>

<p>There are some potential workarounds <a href="https://stackoverflow.com/questions/986826/how-to-do-a-regular-expression-replace-in-mysql">listed here</a>, too.</p>

CC BY-SA 3.0
2017-12-19T15:06:43.647Z
As of MariaDB 10+ regex is supported, would be really nice to include this in CraftCMS 3 as an option for MariaDB users: https://stackoverflow.com/a/26179601/776167
hisnameisjimmy
CC BY-SA 3.0
2014-06-30T23:47:22.333Z
Yeah the more I researched, the less hope I had that there was a solution for it. Guess the easiest would be to dump out the db & do in directly in my IDE?
Seán O'Grady
CC BY-SA 3.0
2014-07-01T07:15:13.603Z
Yeah, that's what I'd do.
Brad Bell
CC BY-SA 3.0
2014-06-30T21:57:12.473Z
2014-06-30T22:44:22.270Z
2014-06-30T22:44:22.270Z
Brad Bell
<p>Does the Find and Replace tool support regex? I need to remove a certain section of an image url for all images in the 'field_body' column.</p>

<p>So if I had an image referenced as such </p>

<pre><code>http://craft.dev/uploads/image-600x400.png
</code></pre>

<p>I would be able to find all images that match that pattern and return the url to be </p>

<pre><code>http://craft.dev/uploads/image.png
</code></pre>

<p>Now I have very little experience with Regex but would this be a safe pattern to use (if I can with Craft that is...)?</p>

<pre><code>(-[0-9]+x[0-9]+)
</code></pre>

CC BY-SA 3.0
2014-06-27T16:49:29.847Z
We already had a very similar question: ["How can I perform a RegEx match in Twig?"](http://craftcms.stackexchange.com/q/228/125)
carlcs
CC BY-SA 3.0
2014-06-27T16:53:41.957Z
Thanks. It is similar I guess, but not entirely the same. I want to permanently replace the content rather than to rely on using twig for something like this. The URL's shouldnt need to change after this replacement process.
Seán O'Grady
CC BY-SA 3.0
2014-06-27T18:46:02.960Z
Sorry, did't read this properly. So your actual files are already renamed and now you want to change that in the db, right? What about using Sequel or sth. to change that in the db directly?
carlcs
CC BY-SA 3.0
2014-06-27T19:02:23.237Z
Sort of. The images were generated by Wordpress from the source image and I want to reference that source image instead of the smaller image, otherwise I'll have 40k photos that I will never use! I could do it directly in the db I guess!
Seán O'Grady
CC BY-SA 3.0
2014-06-27T22:52:35.233Z
Just another question. What is sth? Also does Sequel Pro (I'm guessing that's what you meant) allow regex replacement? I know native MySQL doesnt allow it,
Seán O'Grady
CC BY-SA 3.0
2014-06-28T10:06:21.437Z
Yes I meant Sequel Pro or sth. (=something :)) like that. Sorry for confusion, also a quick google search made me aware of the fact, that there is no built-in regex functionality in MYSQL or Sequel Pro. There are plugins available, but maybe this is all a little overkill for your single task. I'd rather export that single table and use an external app for the regex (I have no experience with that). I suppose you already entered content to some asset fields and/or related your assets to entries, so that a reimport of your full-size assets is no option?!
carlcs
<regex>
Can I use Regex in the Find and Replace tool?
# Can I use Regex in the Find and Replace tool?

(Asked by: username_0 on 2014-06-27)

Does the Find and Replace tool support regex? I need to remove a certain section of an image url for all images in the 'field_body' column.
So if I had an image referenced as such 
http://craft.dev/uploads/image-600x400.png

I would be able to find all images that match that pattern and return the url to be 
http://craft.dev/uploads/image.png

Now I have very little experience with Regex but would this be a safe pattern to use (if I can with Craft that is...)?
(-[0-9]+x[0-9]+)

**Tags:** regex

> **Comments:**
> **username_1**: We already had a very similar question: ["How can I perform a RegEx match in Twig?"](http://craftcms.stackexchange.com/q/228/125)  
> **username_0**: Thanks. It is similar I guess, but not entirely the same. I want to permanently replace the content rather than to rely on using twig for something like this. The URL's shouldnt need to change after this replacement process.  
> **username_1**: Sorry, did't read this properly. So your actual files are already renamed and now you want to change that in the db, right? What about using Sequel or sth. to change that in the db directly?  
> **username_0**: Sort of. The images were generated by Wordpress from the source image and I want to reference that source image instead of the smaller image, otherwise I'll have 40k photos that I will never use! I could do it directly in the db I guess!  
> **username_0**: Just another question. What is sth? Also does Sequel Pro (I'm guessing that's what you meant) allow regex replacement? I know native MySQL doesnt allow it,  
> **username_1**: Yes I meant Sequel Pro or sth. (=something :)) like that. Sorry for confusion, also a quick google search made me aware of the fact, that there is no built-in regex functionality in MYSQL or Sequel Pro. There are plugins available, but maybe this is all a little overkill for your single task. I'd rather export that single table and use an external app for the regex (I have no experience with that). I suppose you already entered content to some asset fields and/or related your assets to entries, so that a reimport of your full-size assets is no option?!  

---

## 2 answers

### Answer by username_3 on 2014-06-30. Score: 6 | Accepted answer

Nope, because MySQL doesn't support RegEx replacements in SQL statements. It's been an [open feature request](http://bugs.mysql.com/bug.php?id=27389) since 2007, so feel free to add your vote.

There are some potential workarounds [listed here](https://stackoverflow.com/questions/986826/how-to-do-a-regular-expression-replace-in-mysql), too.

> **Comments:**
> **username_0**: Yeah the more I researched, the less hope I had that there was a solution for it. Guess the easiest would be to dump out the db & do in directly in my IDE?  
> **username_3**: Yeah, that's what I'd do.  
> **username_2**: As of MariaDB 10+ regex is supported, would be really nice to include this in CraftCMS 3 as an option for MariaDB users: https://stackoverflow.com/a/26179601/776167  

---

### Answer by username_2 on 2017-12-19. Score: 1

I'll add my two cents here, since it appears you are removing Wordpress created images (which I also did).
I wrote a regex initially to find all these duplicated files (this command works specifically on OSX, but is pretty portable):
find -E . -regex '.*\-[0-9]{1,4}\x[0-9]{1,4}\.(png|gif|jpg)$'

I then wrote a minor change to delete them:
find -E . -regex '.*\-[0-9]{1,4}\x[0-9]{1,4}\.(png|gif|jpg)$' -delete

I figure you can use this same regex pattern to find/replace in a database dump locally, which this answer here points to: https://stackoverflow.com/a/9456574/776167


---

