List:General Discussion« Previous MessageNext Message »
From:hsv Date:October 13 2012 12:51pm
Subject:Re: Extract text from string
View as plain text  
>>>> 2012/10/12 17:56 +0100, Neil Tompkins >>>>
Is there such a way in a MySQL query to extract the text "this is a test"
from the following strings as a example

<strong><a href="http://www.domain.com/" class="link">this is a
test</a></strong>
<strong><a href="http://www.domain.com/" title="this is a test"
class="link">link</a></strong> 
<<<<<<<<
Amongst the built-in functions there isn't much; for the former example, if the string is
"s", this works:
SUBSTRING_INDEX(SUBSTRING_INDEX(s, '>', -3), '<', 1)
; for the latter, if "t":
SUBSTRING_INDEX(SUBSTRING_INDEX(t, '"', -4), '"', 1)
.

If you want a real HTML parser that discards everything but arbitrary strings, you have to
get & install your own.

Thread
Extract text from stringNeil Tompkins12 Oct
  • RE: Extract text from stringRick James12 Oct
  • Re: Extract text from stringSinger Wang12 Oct
  • Re: Extract text from stringhsv13 Oct