+ 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
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. 

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