0

There are several image tags in a html description row there is a problem as the images uploaded had some spaces in between

for ex:

<div class="colUnitImg">
                <img src="{images_home}images/corsair/VENGEANCE-8GB-DDR4-C16-RAM/description/heat spreader.jpg" alt="Heat Spreader">
</div> 

I want to change this into

<div class="colUnitImg">
                <img src="{images_home}images/corsair/VENGEANCE-8GB-DDR4-C16-RAM/description/heat-spreader.jpg" alt="Heat Spreader">
            </div>

as you can see the image file name has a space and i want it to turn the white space in hyphen

I have run a unix based that recursively did the changes in the file name on the server but I want a mysql query to make the changes in the mysql table.

UPDATE product_description
SET description = REGEXP_REPLACE(description, '(?<=<img[^>]*src="[^"]*[/{][^"/]*) (?=[^"]*"[^>]*>)', '-')
WHERE description REGEXP '<img[^>]src="[^"]*[/{][^"/] [^"]*"[^>]*>';

I used this but my version of mysql is 5.6 and I dont have admin rights to update the version.

I also did some tweeking with the SUBSTRING_INDEX function in mysql but it deleted the image tags in the row.

I just want the file name white space to be replaced with hyphens

Aman Verma
  • 11
  • 3
  • Check this link https://stackoverflow.com/questions/1806949/mysql-query-to-replace-spaces-in-a-column-with-underscores – Yogendra Jun 21 '23 at 09:00
  • Does this answer your question? [MySQL query to replace spaces in a column with underscores](https://stackoverflow.com/questions/1806949/mysql-query-to-replace-spaces-in-a-column-with-underscores) – Yogendra Jun 21 '23 at 09:00
  • @Yogendra please read the question the answer you sent will replace any whitespace to - – Aman Verma Jun 21 '23 at 11:12

1 Answers1

0

UPDATE product_description SET description = REPLACE( description, SUBSTRING_INDEX( SUBSTRING_INDEX(description, '/', -2), '.', '1' ), REPLACE( SUBSTRING_INDEX( SUBSTRING_INDEX(description, '/', -2), '.', '1' ), ' ', '-' ) ) WHERE description like '%img%';