-1

I am trying to remove all links from column_content in my table_name. Links look like:

<a style="text-decoration:none" href="/index.php?o=oda-res-site">.</a>

and href="........" is different in each record.

Can you help with a statement with wildcards that will clean all links <a ..../a> ?

I tried this:

UPDATE MyTable
SET StringColumn = REPLACE (StringColumn, 'SearchForThis', 'ReplaceWithThis')

but I could not found the proper wildcards to include -if possible- all links.

Thank you I use phpMyadmin

geoplous
  • 217
  • 2
  • 11

2 Answers2

0

If it's SQL Server you're using, REPLACE doesn't handle wildcards or regex so you have to loop using PATINDEX instead.

Regex pattern inside SQL Replace function?

Community
  • 1
  • 1
George Dando
  • 444
  • 2
  • 11
0

Hm... If I got you right, the solution shouldn't be that difficult. Following a sample code basing on your example:

DECLARE @MyString nvarchar(250) = N'<a style="text-decoration:none" href="/index.php?o=oda-res-site">.</a>';
SELECT @MyString as MyOldString, LEFT(@MyString, CHARINDEX('href="', @MyString)+5) + '">.</a>' as MyNewString
Jaydip Jadhav
  • 12,179
  • 6
  • 24
  • 40
Tyron78
  • 4,117
  • 2
  • 17
  • 32
  • Thanks for your try but it didn't work. I have basic knowledge in mysql, so I just copy paste the above at phpMyAdmin > sql tab. The error is: #1064 - You have an error in your SQL syntax; – geoplous Apr 16 '16 at 04:32
  • Oh, ok, if it's mysql, the query might require some modification. I tested it on Sqlserver. Guess you might need to use instring or similar instead of charindex. Im not that familiar with mysql. – Tyron78 Apr 16 '16 at 15:49