Note that there are some explanatory texts on larger screens.

plurals
  1. PORegular Expressions - how to replace a character within quotes
    primarykey
    data
    text
    <p>Hello regular expression experts,</p> <p>There has never been a string manipulation problem I couldn't resolve with regular expressions until now, at least in an elegant manner using just one step. Here is the sample data I'm working with:</p> <blockquote> <p>0,"section1","(7) Delivery of 'certificate' outside the United States prohibited. Since both section 339 of the 1940 statute, 68/ and section 341 of the present law are explicit in their statement that the certificate shall be furnished the citizen, only if such individual is at the time within the United States, it is clear that the document could not and cannot be delivered outside the United States.",http://www.google.com/</p> <p>1,"section2",,http://www.google.com/</p> <p>2,"section3",",,",http://www.google.com/</p> </blockquote> <p>This is a section of a much larger CSV file. With one elegant regular expression, I'd like to replace only all the commas that occur within the double quotes with an underscore character (_). It is important that the regular expression does NOT replace any commas outside the quotes because that would mess up the CSV data structure.</p> <p>Thanks, Tom</p> <p>--</p> <p>CLARIFICATION:</p> <p>Sorry guys, I posted the question without fully clarifying my situation, so let me summarize below:</p> <ul> <li>Assume that quotes within quotes are already escaped (quotes within quotes in a CSV file saved by Excel are represented by <code>""</code> or <code>"""</code> etc., so they are easily replaced beforehand).</li> <li>I am working within JavaScript.</li> </ul> <p>Using the sample text above, here is what it SHOULD look like after running the regular expression replacement (there should be a total of 5 replacements):</p> <blockquote> <p>0,"section1","(7) Delivery of 'certificate' outside the United States prohibited. Since both section 339 of the 1940 statute_ 68/ and section 341 of the present law are explicit in their statement that the certificate shall be furnished the citizen_ only if such individual is at the time within the United States_ it is clear that the document could not and cannot be delivered outside the United States.",http://www.google.com/</p> <p>1,"section2",,http://www.google.com/</p> <p>2,"section3","__",http://www.google.com/</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload