How to match words that start with S in a string with VB.NET

1 Answer

0 votes
Imports System
Imports System.Text.RegularExpressions

Public Module Module1
	Sub WordsStartWith(ByVal str As String, ByVal expr As String)
		Dim mc As MatchCollection = Regex.Matches(str, expr)
		Dim word As Match

		  For Each word In mc
			 Console.WriteLine(word)
		  Next word
  	End Sub
    Public Sub Main()
	    Dim str As String = "Stack VB sold net Safe c programming s saber S"
	
		WordsStartWith(str, "\bS\S*")
    End Sub
End Module
 


 
 
' run:
'
' Stack
' Safe
' S
'

 



answered Oct 26, 2022 by avibootz
edited Oct 26, 2022 by avibootz
...