Create a query for special characters MINUS . and - in access - ms-access

I am using this Like "[!A-Z0-9]", to find special characters in mailing namelines however it picks up "." and "-" which I do not want to see

Try this instead:
Like "*[!A-Z0-9.-]*"
If you want to check email addresses on validity, I'd suggest using VBA and Regular Expressions.
I guess there's plenty of posts on Stackoverflow regarding checking email addresses.
Otherwise have a look as this article on Geeksengine:
How to validate email addresses

SELECT Temp_File.SFID, Temp_File.SFACCID, Temp_File.VIS_NUM, Temp_File.DEAR_LINE, Temp_File.NAMELINE1, Temp_File.NAMELINE2, Temp_File.SALUT, Temp_File.SFID, Temp_File.SFACCID, Temp_File.VIS_NUM, Temp_File.First, Temp_File.MIDDLE, Temp_File.Last, Temp_File.SUFFIX, Temp_File.SPO_VIS, Temp_File.SPOUSE_SALUT, Temp_File.SPOUSE_FIRST, Temp_File.SPOUSE_MIDDLE, Temp_File.SPOUSE_LAST, Temp_File.SPOUSE_SUFFIX
FROM Temp_File
WHERE (((Temp_File.NAMELINE2) Like "[!A-Z0-9-.]")) OR (((Temp_File.NAMELINE1) Like "[!A-Z0-9-.]"));

Related

mySQL query and match entire e-mail address

In a mySQL query I use something like this to search for matches
SELECT * FROM clients WHERE email = keyword
When there is an e-mail without a hyphen - like foo#domain.com and the keyword is foo then mySQL easily presents me the correct result.
But when there is a hyphen - in the e-mail like foo-bar#domain.com and the keyword is foo-bar mySQL present me all entries with foo. This is also true with #.
Is there a workaround avaliable to query and match for an entire e-mail adress including - and # sign ?
Try to use Asci code for HTML table code

Search within Mysql with special chars

If I have a table files and it has a column title, and some of the titles are in this format:
google: and facebook
stack: overflow
Now I'm trying to add search functionality in my app, which executes a LIKE '%word%' query. But if people search google and facebook it doesn't find anything, unless they specifically search for google: and facebook.
I know what LIKE does and why it doesn't give the results I'm looking for, I'm just asking if there's a way to search in mysql table and ignoring special chars like : ' - . , " etc.
Thanks.
Use REPLACE function prior to comparison.
... REPLACE( fieldname, ':', '') LIKE %word%
Alternative is to replace all spaces in the search string with '%' or you explode the search string (space as separater) and connect the different parts with an OR statement.
You can work with regular expressions
MYSQL Manual

Isolate an email address from a string using MySQL

I am trying to isolate an email address from a block of free field text (column name is TEXT).
There are many different variations of preceding and succeeding characters in the free text field, i.e.:
email me! john#smith.com
e:john#smith.com m:555-555-5555
john#smith.com--personal email
I've tried variations of INSTR() and SUBSTRING_INDEX() to first isolate the "#" (probably the one reliable constant in finding an email...) and extracting the characters to the left (up until a space or non-qualifying character like "-" or ":") and doing the same thing with the text following the #.
However - everything I've tried so far hasn't filtered out the noise to the level I need.
Obviously 100% accuracy isn't possible but would someone mind taking a crack at how I can structure my select statement?
There is no easy solution to do this within MySQL. However you can do this easily after you have retrieved it using regular expressions.
Here would be a an example of how to use it in your case: Regex example
If you want it to select all e-mail addresses from one string: Regex Example
You can use regex to extract the ones where it does contain an e-mail in MySQL but it still doesn't extract the group from the string. This has to be done outside MySQL
SELECT * FROM table
WHERE column RLIKE '\w*#\w*.\w*'
RLIKE is only for matching it, you can use REGEXP in the SELECT but it only returns 1 or 0 on whether it has found a match or not :s
If you do want to extract it in MySQL maybe this other stackoverflow post helps you out. But it seems like a lot of work instead of doing it outside MySQL
Now in MySQL 5 and 8 you can use REGEXP_SUBSTR to isolate just the email from a block of free text.
SELECT *, REGEXP_SUBSTR(`TEXT`, '([a-zA-Z0-9._%+\-]+)#([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,4})') AS Emails FROM `mytable`;
If you want to get just the records with emails and remove duplicates ...
SELECT DISTINCT REGEXP_SUBSTR(`TEXT`, '([a-zA-Z0-9._%+\-]+)#([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,4})') AS Emails FROM `mytable` WHERE `TEXT` REGEXP '([a-zA-Z0-9._%+\-]+)#([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,4})';

Find email links in HTML using MySQL

The HTML is stored within MySQL. What I need to do is find out if there are href links containing an email AND do not have mailto: prefixed to the email. Can this be done in MySQL?
This should be found by the query:
... user1#example.com ...
but not this one:
... user2#example.com ...
Note: I can use PHP/Python and parse the HTML if required, but I'm hoping there is a faster/easier way to do this by only using MySQL.
Bonus Question:
Can you use the above query in an update to add the missing mailto?
You can use MySQL REGEXP to find if there are any emails without the mailto.
SELECT * FROM 'table' WHERE 'column' REGEXP 'href\=\"[A-Z0-9._%+-]+#[A-Z0-9.-]+\.[A-Z]{2,4}\"'
I believe that regex should match anything in this format: href="asdf#asdf.com"
But it won't match: href="mailto:asdf#asdf.com"

using regex in sqlite or mysql

I'm using sqlite3 to try and find users who have an e-mail address that is either with Gmail, Yahoo or Hotmail. It needs to do this just on the basis of the first part of the domain, so I want any address that had the #yahoo to be accepted.
It appears from documentation that it is not possible to use a regular expression when querying an sqlite database. Is there any elegant way of doing something similar? It doesn't seem to be possible to use a "like/in" with multiple options (eg: LIKE (%#yahoo%, %#gmail%, %#hotmail%)?
Failing that, I may switch over to MySQL for a reg exp as I want to keep the solution simple and elegant and DB isn't a major factor. How would said regexp query be written in MySQL?
You can't use multiple "LIKE" in that way but you can use:
(email LIKE "%#yahoo%" OR email LIKE "%#gmail%" OR ....)
you can use the way Nemoden is using or something like this (not tested)
WHERE email REGEXP '[\w\.]+#(yahoo|gmail|ymail|hotmail)\.(com|ru|co\.uk)'
This would be much faster because LIKE %string% OR ... is very slow and doesnt use any indexes(dont know if REGEXP uses indexes tho).
I think you might want something like this (RLIKE function):
WHERE email RLIKE '^[A-Z0-9._%+-]+#[A-Z0-9.-]+\.([A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum|travel)$'
If you use whatever_cs (case sensitive collation), use a-zA-Z instead of A-Z.
You can also get rid of ^ and $ in the regex. ^ means "starts with" and $ means "ends with"
UPDATE:
'.*#(gmail|hotmail|yahoo)\.[A-Z]{2,4}'