I need to break line after comma using regex(another method is welcome too)
function breakLineAfterComma(){
let Text = "This is an Example. Break Line Here"
Text.replace('regex here')
return Text;
}
You can use String.replace to replace all periods and a space with a newline:
function breakLineAfterComma(){
let Text = "This is an Example. Break Line Here. Break Line Here"
return Text.replace(/\. /g, "\n");
}
console.log(breakLineAfterComma())
You can also use String.replaceAll:
function breakLineAfterComma(){
let Text = "This is an Example. Break Line Here. Break Line Here"
return Text.replaceAll(". ", "\n");
}
console.log(breakLineAfterComma())
it's possible to use regex and replace "." with a break.
here is the reusable function example
function breakLineAfterComma(text){
return text.replace(/\./g, '\n');
}
const content = "This is an Example. Break Line Here"
const a = breakLineAfterComma(content);
console.log(a);
function splitText(text){
text = "This is an Example. Break Line Here";
return text.split('. ').join('.\n');
// This is an Example.
// Break Line Here
}