function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ketan vinodrai mehtaketan vinodrai mehta 

RegEx to replace newline characters between two double quotes.

Hi All,
    I am looking for a solution to replace all newline character occuring between two double quotes. I have already referred below URL  https://stackoverflow.com/questions/26337474/regexp-to-find-replace-newlines-within-double-quotes-not-affecting-newlines-out and tried to execute below code but seems like something is missing. 

String rawString = Label.TestLable;
String result = rawString.Replace('([^"\n]*)\r?\n(?!(([^"]*"){2})*[^"]*$)/g', '<br>');

The TestLabel custom label has string with multiple newline characters and enclosed within double quotes below:

"
Hello Team
Requesting you to join us at marathod event happening at below venue

"

And the out put expected is:
Hello Team <br>Requesting you to join us at marathod event happening at below venue


 
karthikeyan perumalkarthikeyan perumal
Hello, 
Use below regex for your output, 
 
String rawString = Label.TestLable;
rawString = rawString .replace(/(?:\r\n|\r|\n)/g, '<br>');

Hope this will work for you. 

Thanks
karthik
 
ketan vinodrai mehtaketan vinodrai mehta
Hi Karthik, Thank you for the response. I have enclosed the expression within a single quote as below: String rawString = Label.TestLable; rawString = rawString.replace('/(?:\r\n|\r|\n)/g', '
'); The provided solution is not working and on the other hand, I do not see you are considering to replace newline characters only within double quotes. Regards, Ketan Mehta
Dinesh Kumar 2220Dinesh Kumar 2220
@ketan vinodrai mehta

Did you find the fix for this , i am still stuck in same issue.