(\w){1,2} matches a non-word character either one or two times. : Match « Regular Expressions « VB.Net Tutorial






Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim pattern As String = "\b(\w+)(\W){1,2}"
      Dim input As String = "this is a test 123."
      For Each match As Match In Regex.Matches(input, pattern)
         Console.WriteLine(match.Value)
         Dim captures As CaptureCollection = match.Groups(2).Captures
         For ctr As Integer = 0 To captures.Count - 1
             Console.WriteLine(captures(ctr).Value)
             Console.WriteLine(Convert.ToUInt16(captures(ctr).Value.Chars(0)).ToString("X4"))
             Console.WriteLine(If(ctr < captures.Count - 1, ", ", ""))
         Next
      Next
   End Sub
End Module








20.6.Match
20.6.1.[\p{P}\d] matches all punctuation and decimal digit characters.
20.6.2.[\s\p{P}] matches all white-space and punctuation.
20.6.3.Negative Character Group: [^]
20.6.4.Any Character: . matches any character except \n
20.6.5.Unicode Category or Unicode Block: \p{}
20.6.6.\W matches any non-word character.
20.6.7.(\w+) matches one or more word characters.
20.6.8.(\w){1,2} matches a non-word character either one or two times.
20.6.9.[aeiou] matches all vowels.
20.6.10.Either/Or Pattern Matching with | section
20.6.11.Regular expression using either/or
20.6.12.Regular expression using character class.
20.6.13.Negative Unicode Category or Unicode Block: \P{}