Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

RegEx Replacement

Posted on 2014-04-09
3
Medium Priority
?
329 Views
Last Modified: 2014-04-09
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"
0
Comment
Question by:WH_Tech
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1500 total points
ID: 39989132
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
 

Author Comment

by:WH_Tech
ID: 39989251
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
 
LVL 35

Assisted Solution

by:Dan Craciun
Dan Craciun earned 500 total points
ID: 39989262
You don't need a regex for that. Just replace '' with ".

HTH,
Dan
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question