Solved

RegEx Replacement

Posted on 2014-04-09
3
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 35

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…

636 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