# Using a regular expression function on SQL Server

Available in...

* Big Data Platform
* Cloud API Services Platform
* Cloud Big Data Platform
* Cloud Data Fabric
* Cloud Data Management Platform
* Data Fabric
* Data Management Platform
* Data Services Platform
* Qlik Talend Cloud Enterprise Edition
* Qlik Talend Cloud Premium Edition
* Real-Time Big Data Platform

## 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 &gt; Indicators &gt; System Indicators &gt; 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.](https://help.qlik.com/talend/en-US/studio-user-guide/Resources/images/regex_function_template1.png)

   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.](https://help.qlik.com/talend/en-US/studio-user-guide/Resources/images/regex_function_template.png)
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 ![Save](https://help.qlik.com/talend/en-US/studio-user-guide/Resources/images/save.svg) 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](https://help.qlik.com/talend/en-US/studio-user-guide/8.0/defining-query-template-for-specific-database) and [Declaring a User-Defined Function in a specific database](https://help.qlik.com/talend/en-US/studio-user-guide/8.0/declaring-user-defined-function-in-specific-database).