L
leeonions
Hi there,
i am trying to use regular expressions to search through a text string
and replace a given whole word.
take the string = "The matsat on the mat!" (bad example i know)
i want to replace the whole word 'mat' with the word 'cat' to give
"The matsat on the cat!"
(matsat was not replaced as only whole word match, cat on the other
hand is replace because non-word characters i.e. !, are allowed)
Given below is the closest i've got using RegExp.replace, with the
following expression
Dim exp As String = "(^|\W+)(mat)($|\W+)"
This correctly identifies whole words (with surrounding non word
charaters) but also replaces the non word characters in the string,
which i wish to preserve.
Can anyone suggest a viable work around or a regular expression that
will match against part of a string without replace the entire of it.
Thanks in advance....
Cheers,
Lee
i am trying to use regular expressions to search through a text string
and replace a given whole word.
take the string = "The matsat on the mat!" (bad example i know)
i want to replace the whole word 'mat' with the word 'cat' to give
"The matsat on the cat!"
(matsat was not replaced as only whole word match, cat on the other
hand is replace because non-word characters i.e. !, are allowed)
Given below is the closest i've got using RegExp.replace, with the
following expression
Dim exp As String = "(^|\W+)(mat)($|\W+)"
This correctly identifies whole words (with surrounding non word
charaters) but also replaces the non word characters in the string,
which i wish to preserve.
Can anyone suggest a viable work around or a regular expression that
will match against part of a string without replace the entire of it.
Thanks in advance....
Cheers,
Lee