Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| ' Visual Basic .NET Document | |
| Option Strict On | |
| ' <Snippet4> | |
| Imports System.Text.RegularExpressions | |
| Module Example | |
| Public Sub Main() | |
| Dim input As String = "<PRIVATE> This is not for public consumption." + vbCrLf + _ | |
| "But this is for public consumption." + vbCrLf + _ | |
| "<PRIVATE> Again, this is confidential." + vbCrLf | |
| Dim pattern As String = "^(?<Pvt>\<PRIVATE\>\s)?(?(Pvt)((\w+\p{P}?\s)+)|((\w+\p{P}?\s)+))\r?$" | |
| Dim publicDocument As String = Nothing | |
| Dim privateDocument As String = Nothing | |
| For Each match As Match In Regex.Matches(input, pattern, RegexOptions.Multiline) | |
| If match.Groups(1).Success Then | |
| privateDocument += match.Groups(1).Value + vbCrLf | |
| Else | |
| publicDocument += match.Groups(3).Value + vbCrLf | |
| privateDocument += match.Groups(3).Value + vbCrLf | |
| End If | |
| Next | |
| Console.WriteLine("Private Document:") | |
| Console.WriteLine(privateDocument) | |
| Console.WriteLine("Public Document:") | |
| Console.WriteLine(publicDocument) | |
| End Sub | |
| End Module | |
| ' The example displays the following output: | |
| ' Private Document: | |
| ' This is not for public consumption. | |
| ' But this is for public consumption. | |
| ' Again, this is confidential. | |
| ' | |
| ' Public Document: | |
| ' But this is for public consumption. | |
| ' </Snippet4> |