Skip to main content Skip to complementary content

Using a regular expression function on SQL Server

Before you begin

  • You have deployed the regular expression function to the SQL server.
  • You have tested the regular expression.
  • You have selected the Profiling perspective.

About this task

Before being able to use regular expressions on analyzed columns in a database, you must first declare the created regular expression function, RegExMatch in this example, in the specified database.
Here is the code used in this example:
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 ;
            }
Using
     }
};

Procedure

  1. In the DQ Repository tree view, expand Libraries > Indicators > System Indicators > Pattern Matching.
  2. Double-click Regular Expression Matching, or right-click it and select Open from the contextual menu.
    The corresponding view displays the indicator metadata and its definition.
    Regular Expression Matching view.
    You must add to the list of databases the database for which you want to define a query template. This query template will compute the regular expression matching.
  3. Click the [+] button at the bottom of the Indicator Definition view.
    An empty row is added at the bottom of the view.
  4. In the new field, click the arrow and select the database for which you want to define the template, Microsoft SQL Server in this example.
  5. Copy the indicator definition of any of the above databases.
  6. Click the Edit... button next to the new field.
    The Edit expression dialog box is displayed.
    Edit expression dialog box.
  7. Paste the indicator definition (template) in the Expression box and then modify the text after WHEN in order to adapt the template to the selected database.
  8. Click OK to proceed to the next step. The new template is displayed in the field.
  9. Click the save icon Save on top of the editor.

Results

For more detailed information on how to declare a regular expression function in Talend Studio, see Defining a query template for a specific database and Declaring a User-Defined Function in a specific database.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!