Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - RegExp question

Reply
 
Old 10-16-2008   #1 (permalink)
PO


 
 

RegExp question

Hi

With New RegExp
.Pattern = "^(?:[AUTI]\d{5}(?:,|$))+$"
.IgnoreCase = True

If .Test(sAvtal) = False Then
Exit Sub
End If
End With

allows for e.g. U12345,A23456

My problem is that there is no limit to the amount of values that can be
entered.
How do I modify the pattern to allow 1 to 5 comma seperated values?

Regards
Pete



My System SpecsSystem Spec
Old 10-16-2008   #2 (permalink)
ekkehard.horner


 
 

Re: RegExp question

PO schrieb:
Quote:

> Hi
>
> With New RegExp
> .Pattern = "^(?:[AUTI]\d{5}(?:,|$))+$"
> .IgnoreCase = True
>
> If .Test(sAvtal) = False Then
> Exit Sub
> End If
> End With
>
> allows for e.g. U12345,A23456
>
> My problem is that there is no limit to the amount of values that can be
> entered.
> How do I modify the pattern to allow 1 to 5 comma seperated values?
>
> Regards
> Pete
>
I *think* a pattern like

^[AUTI]\d{5}(?:,[AUTI]\d{5}){0,4}$

will do what want.

To make sure/experiment, use:

Dim sG1 : sG1 = "U12345"
Dim sG2 : sG2 = "A23456"
Dim sB1 : sB1 = "X23456"
Dim sB2 : sB2 = "A2345"
Dim aTests : aTests = Array( _
False, "" _
, True , Join( Array( sG1 ), "," ) _
, False, " " & Join( Array( sG1 ), "," ) _
, True , Join( Array( sG1, sG2, sG1, sG2, sG1 ), "," ) _
, False, Join( Array( sG1, sG2, sG1, sG2, sG1 ), ", " ) _
, False, Join( Array( sG1, sG2, sG1, sG2, sG1, sG2 ), "," ) _
, True , Join( Array( sG1, sG2, sG1 ), "," ) _
, False, Join( Array( sG1, sB1, sG1 ), "," ) _
, False, Join( Array( sG1, sB2, sG1 ), "," ) _
)
Dim oRE : Set oRE = New RegExp
oRE.Global = True
oRE.IgnoreCase = True
Dim sX5N : sX5N = "[AUTI]\d{5}"
oRE.Pattern = "^" & sX5N & "(?:," & sX5N & "){0,4}$"
WScript.Echo oRE.Pattern

Dim nIdx
For nIdx = 0 To UBound( aTests ) Step 2
Dim bExp : bExp = aTests( nIdx + 0 )
Dim sInp : sInp = aTests( nIdx + 1 )
Dim bRes : bRes = oRE.Test( sInp )
WScript.Echo Left( CStr( bExp = bRes ) & Space( 7 ), 7 ) _
& Left( CStr( bRes ) & Space( 7 ), 7 ) _
& ">" & sInp & "<"
Next


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
RegExp to find hex value 0D fails VB Script
RegExp to find hex value 0D fails Vista General
RegExp pattern to escape ALL special characters (but exclude unicodechars) VB Script
new regExp VB Script
Dual boot system question and family deal discount question Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46