RegEx Replacement

Need to remove a bunch of single ' and double " from some text strings.  I'm using C# 2013 to loop the DB and the only real catch stopping me from using a simple replace is the fact I need the single ' and double " to remain if the the value on the left is a number.  I'm assuming this can be done with a negative lookback, but I'm not have much luck.  Here is a sample string.

"2 PIECES 1/4" THICK GLASS WITH A 1 1/4" BEVEL"
WH_TechAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
käµfm³d 👽Connect With a Mentor Commented:
Yes, a negative lookback should be what you need:

string result = Regex.Replace(original, "(?<!\\d)['\"]", string.Empty);

Open in new window


Also, if you'd like an explanation of lookaround, you might take a look at the article I wrote on the subject.
0
 
WH_TechAuthor Commented:
I found one exception.  Sometimes there are 2 single quotes instead of a double quote.  How can I replace the sequential single quotes with one double quote?
0
 
Dan CraciunConnect With a Mentor IT ConsultantCommented:
You don't need a regex for that. Just replace '' with ".

HTH,
Dan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.