WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

RegularExpressions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

RegEx

 Keywords: IsMatch Regular Expression RegEx System.Text.RegularExpressions.Regex 

;***************************************************************************
;**   RegEx IsMatch Example
;**
;** Purpose: Indicates whether the regular expression finds a match in the input string.
;** Inputs: Pattern and Text
;** Outputs: Results in a message box
;** Reference: 
;**       REQUIRES WinBatch 2013A or newer 
;**
;** Developer: Stan Littlefield, Deana Falk 2013.05.06
;*************************************************************************** 
If Version( )< '2013A' 
   Pause('Notice', 'Need 2013A or Newer Version of WinBatch')
   Exit 
EndIf
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Load assemblies into the WinBatch process.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; mscorlib assembly is automatically loaded by WinBatch when the CLR is loaded.
; ObjectClrOption ('use','mscorlib, version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
ObjectClrOption( 'use', 'System, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089')

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Prompt for input
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Pattern = "^[a-zA-Z0-9]\d{2}[a-zA-Z0-9](-\d{3}){2}[A-Za-z0-9]$" 
Text="1298-673-4192,A08Z-931-468A,A90-123-129X,12345-KKA-1230,0919-2893-1256"

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Create a class implemented by a managed assembly.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oReg = ObjectClrNew('System.Text.RegularExpressions.Regex',Pattern)
oReg.CacheSize = ObjectType("ui2",30) ;2-byte unsigned integer.

n = ItemCount( Text, ',' )
For i=1 To n
   cM =' matches'
   txt = ItemExtract( i, Text, ',' )
   m = oReg.IsMatch( txt )
   If m==0 Then cM=' Does Not Match'
   Message( '', txt:cM )
Next
Exit


Article ID:   W17843
Filename:   RegEx.txt
File Created: 2013:05:06:12:51:06
Last Updated: 2013:05:06:12:51:06