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

181
Views
\r\n not splitting string in javascript

I have a string which is multiline. I update this on SFL case object field. When i extract the same from database using SOQL, it appends \r\n\r\n whenever multiline text is found. I tried using different regex expressions with split(\r\n) or split(\r\n) and some more as suggested in different articles, but none of them are helping.

split(\r\n) it removes \r\n from my string but replaces it with ,,

What approach should i take.

SFL input--> This is line 1
             This is line 2

Output--> This is line 1 \r\n\r\n  This is line 2
when using split output--> This is line 1 ,,This is line 2

expected-->
This is line 1
This is line 2

Please help.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Is it possible to split by '\nand then.trim()` each string?

Or you can try this:

var str = `hello
world

ok`;
var arr = str.split(/\r?\n/)
console.log(arr)

about 4 years ago · Juan Pablo Isaza Report

0

Use a character set in the regular expression separator.

const string = 'This is line 1\r\n\r\nThis is line 2'
const result = string.split(/[\r\n]+/)
console.log(result)

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!