On 9 Nov 2004 08:47:48 -0800, Gary McCullough wrote:
What I want to do sounds simple, but it's defeating me. I want to
substitute all occurences of a colon : character in a string with an @
character -- unless the : occurs within a single or double-quoted
substring. Surely this can be done with regular expressions? Any regex
gurus know how to do it?
This pattern will find all occurrences of a particular charcter except
where it occurs between quotation marks.
This example finds the occurrences of the colon character except where it
appears within quotation marks. If you want single quotes, then change the
\x22 to \x27
Dim sPattern As String = ":(?=([^\x22]*\x22[^\x22]*\x22)*(?![^\x22]*\x22))"
Dim sInput As String = "Meeting tomorrow : 11AM ""Example: 1"""
Dim mc As New MatchCollection =
Regex.Matches(sInput,sPattern,RegExOption.Explicit Capture)
The match collection here should contain only one item the location of the
colon after the word tomorrow.
If you use the replace function:
Dim sResult As string = Regex.Replace(sInput, sPattern, "@")
'sResult = "Meeting tomorrow @ 11AM "Example: 1""
Perhaps this will help you.
--
Chris
dunawayc[AT]sbcglobal_lunchmeat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.