![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 > ^[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 Specs![]() |
![]() |
| 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 | |||