javascript - 如何使用正则表达式在逗号后换行
问题描述
我需要使用正则表达式在逗号后换行(也欢迎使用另一种方法)
function breakLineAfterComma(){
let Text = "This is an Example. Break Line Here"
Text.replace('regex here')
return Text;
}
解决方案
您可以使用String.replace
换行符替换所有句点和空格:
function breakLineAfterComma(){
let Text = "This is an Example. Break Line Here. Break Line Here"
return Text.replace(/\. /g, "\n");
}
console.log(breakLineAfterComma())
您还可以使用String.replaceAll
:
function breakLineAfterComma(){
let Text = "This is an Example. Break Line Here. Break Line Here"
return Text.replaceAll(". ", "\n");
}
console.log(breakLineAfterComma())
推荐阅读
- if-statement - Tableau 中的 IF、THEN、ELSEIF 语句
- c# - C# NpgsqlException 模拟起订量
- makefile - Makefile - suddenly needs .o rule after editing makefile
- sql - 在订单之间添加一个空行
- javascript - 遍历 React 中的对象
- python - Django - 组合多个变量
- excel - 使用串联公式执行代码时应用程序定义或对象定义的错误
- javascript - 无法使用参数导航到不同的页面
- jquery - 单击时初始化 Flatpickr
- php - php日期移到下个月