Proprietà Pattern

Definisce il pattern dell'espressione regolare.

Uso della proprietà

Sintassi: Object.Pattern = "<PATTERN STRING>"

Esempi

regExpObj.Pattern = "^\d{4}_\d{6}$" ' Restituisce le stringe corrispondenti nel formato 1234_567890

regExpObj.Pattern = "\b\d{2}/\d{2}/\d{4}\b" 'Restituisce le date corrispondenti nel formato MM/DD/YYYY

Esempio
Dim regex, inputText
Set regex = CreateObject("VBScript.RegExp")
regex.Pattern = "^\d{4}_\d{6}$"   ' Match strings in the format 1234_567890
inputText = "1234_567890"
' Check if the inputText matches the pattern
If regex.Test(inputText) Then
    'Valid Format Related Coding
Else
    'Invalid format Related Coding
End If

Nel codice precedente, il pattern ^\d{4}_\d{6}$ fa sì che inputText sia esattamente nel formato a 4 cifre, seguito da un carattere di sottolineatura (_) e da 6 cifre alla fine. Se inputText corrisponde al pattern, verrà attivato il flusso di codice della sezione Valid Format. In caso contrario, il controllo passerà al flusso del codice relativo alla sezione Invalid Format.