Ecco un esempio di creazione di una tabella con regole specifiche per la posta con indirizzo (regexp). Quindi un esempio con modello di query sql (Regexp). Con questo dovresti essere in grado di fare quello che vuoi
Crea tabella con regexp
create table Contacts (
FirstName nvarchar(30),
LastName nvarchar(30),
EmailAddress nvarchar(30) CHECK (dbo.RegExMatch('[a-zA-Z0-9_\-]example@sqldat.com([a-zA-Z0-9_\-]+\.)+(com|org|edu|nz)', EmailAddress)=1),
USPhoneNo nvarchar(30) CHECK (dbo.RegExMatch('\([1-9][0-9][0-9]\) [0-9][0-9][0-9]\-[0-9][0-9][0-9][0-9]', UsPhoneNo)=1))
INSERT INTO [talend].[dbo].[Contacts]
([FirstName]
,[LastName]
,[EmailAddress]
,[USPhoneNo])
VALUES
('Hallam'
,'Amine'
,'example@sqldat.com’
,'0129-2090-1092')
,( 'encoremoi'
,'nimportequoi'
,'example@sqldat.com'
,'(122) 190-9090')
GO
Esegui richiesta sql con regexp
SELECT [FirstName]
,[LastName]
,[EmailAddress]
,[USPhoneNo]
FROM [talend].[dbo].[Contacts]
where [talend].[dbo].RegExMatch([EmailAddress],'[a-zA-Z0-9_\-]example@sqldat.com([a-zA-Z0-9_\-]+\.)+(com|org|edu|nz|au)') = 1
Codice funzione
using System;
using Microsoft.SqlServer.Server;
using System.Text.RegularExpressions;
public partial class RegExBase
{
[SqlFunction(IsDeterministic = true, IsPrecise = true)]
public static int RegExMatch( string matchString , string pattern)
{
Regex r1 = new Regex(pattern.TrimEnd(null));
if (r1.Match(matchString.TrimEnd(null)).Success == true)
{
return 1 ;
}
else
{
return 0 ;
}
}
};
Per ulteriori spiegazioni, mostra qui questo tutorial -> https://www.google.ch/url?sa=t&rct=j&q=&esrc=s&source=web&cd=6&ved=0CGkQFjAF&url=http%3A%2F%2Fwww.talendforge.org%2Fbugs%2Ffile_download.php%3Ffile_id%3D4729%26type%3Dbug&ei=f8C9UKTMBNSN4gTo0IHYDg&usg=AFQjCNG-ezRtC9TdcJXuXGl4T8KX4zbUww&sig2=Fpgm5UTYOK4dpsaMfNCCyQ&cad=rja
Spero che questo ti aiuti