How to Replace <p> to \n

Yongyood Singta
Tera Contributor

I have a string in html field such as the following:

<p><strong>Impact&nbsp;</strong><br /><strong>Test1 : </strong> abcde</p>

 

I want to remove all html tag and still keep the format in field (just only spacebar & new line (Enter))

Example Result i want : 

Impact
Test1 : abcde

 

my code :

var str = myStr.getHTMLValue().replace(/<\/?[^>]+(>|$)/g, " ");
 
Result : Impact Test1 : abcde

 

1 ACCEPTED SOLUTION

Sujatha V M
Kilo Patron
Kilo Patron

@Yongyood Singta : New Line - "\n" 

 

Did you try to replace it as, var str = myStr.getHTMLValue().replace(/<\/?[^>]+(>|$)/g, "\n");

 

SujathaVM_0-1712251833017.png

 

Note: Might require some adjustments on the regex format. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

View solution in original post

2 REPLIES 2

Sujatha V M
Kilo Patron
Kilo Patron

@Yongyood Singta : New Line - "\n" 

 

Did you try to replace it as, var str = myStr.getHTMLValue().replace(/<\/?[^>]+(>|$)/g, "\n");

 

SujathaVM_0-1712251833017.png

 

Note: Might require some adjustments on the regex format. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

It work !! Thank you so much.