On 07-04-2021 16:50, Paulo Geloramo wrote:
> Simple regular expression to check an email list:
> ([a-z0-9\_\-\.]+@[a-z0-9\_\-\.]+[,|;]?)*
A word of warning: the actual syntax of valid email addresses is a lot
more complex and - IIRC - is not a regular language so cannot be
captured using a regular expression.
Using a regular expression to check email addresses can exclude
addresses that are actually valid.
>
a...@server.com;
he...@server.com;
dmi...@server.com
>
> I tested on the site
https://regexr.com and passed.
>
> Firebird 2.5.9 and 3.0.7
> In Firebird I'm doing the command below this is working for most.
>
> Failed when email has a minus sign -
> Any suggestion?
>
> SELECT *
> FROM CLIENT
> WHERE EMAIL NOT SIMILAR TO '([a-z0-9\_\-\.]+@[a-z0-9\_\-\.]+[,|;]?)*'
The problem is that you seem to want to use `\` as the escape character,
but you haven't actually specified an escape character, as a result, the
`\` in your character class is just that, a `\`, and not an escape. In
addition, in the SQL regular expression language, the `.` is not a
special character, so it doesn't need to be escaped (and attempting to
do so will result in an error).
You need to add an escape clause (escape '\') and remove the `\` before
the `.`:
SIMILAR TO '([a-z0-9\_\-.]+@[a-z0-9\_\-.]+[,|;]?)*' escape '\'
Also, given the underscore has no special meaning in a character class,
it doesn't need to be escaped; this means you can use:
SIMILAR TO '([a-z0-9_\-.]+@[a-z0-9_\-.]+[,|;]?)*' escape '\'
To avoid case-sensitivity issues (i.e. you specify a-z, but not A-Z),
I'd recommend using the predefined class [:ALNUM:]:
SIMILAR TO '([[:ALNUM:]_\-.]+@[[:ALNUM:]_\-.]+[,|;]?)*' escape '\'
Mark
--
Mark Rotteveel