417 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


Using Patterns


Using Patterns




This examples divides the e-mail field in two parts using the pattern *@*.


  
  
    
    
    
    
  
    <#DATASET ALIAS="OPEX" QUERYID="19">
     
       
       
       
       
           
    <#/DATASET>
  
Full Name e-mail User Name Server
<#USERNAME/> <#EMAIL/> <#EMAIL PATTERN="*@*" PATTERNINDEX="1"/> <#EMAIL PATTERN="*@*" PATTERNINDEX="2"/>
 
  

  

Another patterns:


   <#SETCOOKIE NAME="Telephone" VALUE="(55) 12 34 56"/>
   <#SETCOOKIE NAME="AreaCode" EXPRESSION="Telephone" PATTERN="(*)*" PATTERNINDEX="1"/>
   <#SETCOOKIE NAME="PHI" VALUE="1.618"/>  
   
  

        
  • Telephone: <#TELEPHONE/> Area code: <#AREACODE/>
        
  • The mantise of PHI(<#PHI/>) is .<#PHI PATTERN="*.*" PATTERNINDEX="2"/>
        
  • Current Year: <#SP_DATE PATTERN="*/*/*" PATTERNINDEX="3"/>
        
  • Current Month: <#SP_DATE PATTERN="*/*/*" PATTERNINDEX="2"/>
        
  • Current Day: <#SP_DATE PATTERN="*/*/*" PATTERNINDEX="1"/>
      




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