42 users using DBSP now!
home -> documentation -> language reference -> PATTERN and PATTERNINDEX property


Description

The PATTERN and PATTERNINDEX property combined returns a substring contained in the base string based on a wildcards pattern.


Syntax

<#DATASET ALIAS="anAlias" QUERYID="aQueryId">


<#field1 PATTERN="aWildCardPattern" PATTERNINDEX="aWildCardIndex"/>


<#/DATASET>


<#VARIABLE1 PATTERN="aWildCardPattern" PATTERNINDEX="aWildCardIndex"/>

 

Applications

Use the PATTERN property in dataset fields and variables for an easy way to obtain substrings based on a wildcard pattern. For example you can use the pattern *@* for obtaining the username and server of an email address. See the examples below for a better understanding of its usage.



Examples

Example 1. Usage of the PATTERN and PATTERNINDEX property.

Source code
<html>
<head>
<title>Using Patterns</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body>
<h1>Using Patterns</h1>
<hr>
<p>This examples divides the e-mail field in two parts using the pattern *@*.</p>
   <table border=1>
   <tr>
     <th>Full Name</th>
     <th>e-mail</th>
     <th>User Name</th>
     <th>Server</th>
   </tr>
    <#DATASET ALIAS="OPEX" QUERYID="19">
      <tr>
        <td><#USERNAME/></td>
        <td><#EMAIL/></td>
        <td><#EMAIL PATTERN="*@*" PATTERNINDEX="1"/></td>
        <td><#EMAIL PATTERN="*@*" PATTERNINDEX="2"/></td>
      </tr>     
    <#/DATASET>
   </table> 
   <hr>
   <p>Another patterns:</p>
   <#SETCOOKIE NAME="Telephone" VALUE="(55) 12 34 56"/>
   <#SETCOOKIE NAME="AreaCode" EXPRESSION="Telephone" PATTERN="(*)*" PATTERNINDEX="1"/>
   <#SETCOOKIE NAME="PHI" VALUE="1.618"/>  
   
   <ul>
     <li> <b>Telephone:</b> <#TELEPHONE/> <b>Area code:</b> <#AREACODE/>
     <li> <b>The mantise of PHI(<#PHI/>) is</b> .<#PHI PATTERN="*.*" PATTERNINDEX="2"/>
     <li> <b>Current Year:</b> <#SP_DATE PATTERN="*/*/*" PATTERNINDEX="3"/>
     <li> <b>Current Month:</b> <#SP_DATE PATTERN="*/*/*" PATTERNINDEX="2"/>
     <li> <b>Current Day:</b> <#SP_DATE PATTERN="*/*/*" PATTERNINDEX="1"/>
   </ul>
</body>
</html>

SQL Sentence No. 19
SELECT * FROM CONTACTS


CONTACTS table.
CREATE TABLE "CONTACTS" (
   "USERNAME"   VARCHAR(128) NOT NULL,
   "EMAIL"   VARCHAR(128) NOT NULL,
   "PHONE"   VARCHAR(32)
);

Test example