I'm trying to find image tags urls in a text field with multiple instances.
I'm currently using this code to extract the URL from the text field:
SUBSTRING(text_field FROM 'src="([^"]*).*')
The problem is it only returns the first instance of a image tag.
Is there a way to return multiple instances of matching from a single query?
Use the function regexp_matches()
with the 'g'
flag, example:
with my_table(text_field) as (
values ('src="first";src="second"')
)
select match[1] as result
from my_table
cross join lateral regexp_matches(text_field, 'src="([^"]*)', 'g') as match
result
--------
first
second
(2 rows)
Read about POSIX Regular Expressions in the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With