Reputation: 33644
I have a table that has a column named 'bio', which is a string of max length 255. Inside this bio I want to search if there's an email contained in it. I want to count how many entries in the table that has an email in the bio column. Is such thing possible to be done via SQL?
To add more clarification, bio is a free form text and I am looking to match the email pattern, and not a specific email.
Upvotes: 0
Views: 76
Reputation: 780929
You can use a query like this:
select count(*)
from mytable
where bio REGEXP '<emailregexp>'
Replace <emailregexp>
with the regular expression you're using to match email patterns. There are dozens of answers for that on SO, e.g.
Using a regular expression to validate an email address
However, most of these questions are about validating an email, which assumes that the entire input field is supposed to be a single email. Make sure you remove the ^
and $
anchors for the ends of the input so that yo look for an email anywhere in the field.
Upvotes: 2