Solved

RegEx Replacement

Posted on 2014-04-09
3
316 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 375 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 34

Assisted Solution

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

HTH,
Dan
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Keyboard 2 33
Regular Expression - checking first 3 positions of a column for numerics. 1 22
Moving code from one TFS branch to another 3 25
InputLanguage 1 25
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

785 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