Hi @Yusuf ,
Since there is no regularity between these substitutions, there seems to be no way to simplify them.
You can choose to put all the patterns and the strings that replace them in an array and use them later like the code below.
Dim input As String = "I am 21 year, There are so much people"
Dim output As String = ""
Dim patterns(2) As String
Dim aims(2) As String
patterns(0) = "\bI am (\d+) year\b"
aims(0) = "I am $1 years old"
patterns(1) = "\bWe met (\d+) years before\b"
aims(1) = "We met $1 years ago"
patterns(2) = "\b(([\w]+\s+){1,4})so much people\b"
aims(2) = "$1so many people"
For i = 0 To patterns.Length - 1
For Each match As Match In Regex.Matches(input, patterns(i))
output += Regex.Replace(match.Value, patterns(i), aims(i)) & Environment.NewLine
Next
Next
Console.WriteLine(output)
Best Regards.
Jiachen Li
----------
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.