Reputation:
Am using the following code
Dim pattern As String = "(a\.? |on\.?)"
dim input as string ="a creation on"
dim output as String=Regex.Replace(input, pattern, " ")
It will give me the output
: creat
but my expected output was: creation
, can anyone suggest me how can i achieve the expected output?
Or suggest me that how can i remove stand alone words specified in the pattern from the input.
Upvotes: 2
Views: 101
Reputation: 174826
Just add a space before on
in your regex and replace the matched characters with an empty string.
Dim pattern As String = "(a\.? | on\.?)"
Upvotes: 1
Reputation: 4665
Dim ResultString As String
Try
ResultString = Regex.Replace(SubjectString, "(^|\s)(a|on|etc)($|\s)", " ", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
Catch ex As ArgumentException
'Syntax error in the regular expression
End Try
Upvotes: 0