0

The Text column of my articles table contains html tags, the query returns a false result when I use a SELECT with LIKE:

Here is my request:

SELECT Text FROM articles Text LIKE '%aaa%'

I then try to remove the html tags before doing the LIKE of the SELECT. I tried using regexp_replace but it doesn't work

(SELECT regexp_replace(Text, '<[^>]*>|&nbsp;', '')

If you could help me. Thanks.

2
  • The only way to ensure you don't get false positives is to parse the html. Don't Do That In SQL. Read this question about extracting text from html in MySQL... stackoverflow.com/questions/70973861/… (Instead, parse the html when the data is being ingested and store it in your DB in a more searchable structure.) Commented Nov 20, 2022 at 23:00
  • 1
    Stripping HTML tags from text is a very complex parsing task requiring a full-featured and hopefully debugged HTML/XML parser. Most people don't attempt it with regular expressions. If you must do it with regular expressions, look for appropriate ones online, and tell your users to expect flaws. Commented Nov 20, 2022 at 23:03

0

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.