Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
Replacing an opening quote when there isn't a closing quote

The following code is replacing opening and closing straight double quotes by opening and closing curly double quotes:

const string = `Not dialogue not dialogue.

"Dialogue dialogue.

"Dialogue dialogue."

"Dialogue," not dialogue. "Dialogue."`

const result = string.replace(/"([^"\n\r]*)"/g, '“$1”')

console.log(result)

How to modify this code so the opening straight double quote in "Dialogue dialogue (second line) is also replaced by an opening curly double quote (without adding a closing curly double quote at the end of the line)?

Desired output:

Not dialogue not dialogue.

“Dialogue dialogue.

“Dialogue dialogue.”

“Dialogue,” not dialogue. “Dialogue.”
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use

const string = `Not dialogue not dialogue.

"Dialogue dialogue.

"Dialogue dialogue."

"Dialogue," not dialogue. "Dialogue."`

const result = string.replace(/"([^"\n\r]*)("|$)/gm, (x,y,z) =>  z == '"' ? `“${y}”` : `“${y}`)

console.log(result)

Details:

  • " - a double quote
  • ([^"\n\r]*) - Group 1: any zero or more chars other than ", CR and LF
  • ("|$) - Group 2: " or end of a line (m makes $ match the end of any line).

The (x,y,z) => z == '"' ? `“${y}”` : `“${y}` replacement replaces with “ + Group 1 value + ” if Group 2 value is ", else, the replacement is “ + Group 1 value.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!