Javascript 我怎样才能做到这一点

Javascript 我怎样才能做到这一点,javascript,regex,Javascript,Regex,我有以下案文: var obj = { text: 'Contrary to popular belief, Lorem Ipsum is not simply random text.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney

我有以下案文:

var obj = 
{
    text: 'Contrary to popular belief, Lorem Ipsum is not simply random text.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source.Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance.The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.'
}
我需要把
新行
放在正确和正确的位置上

我试试这个:


var obj=
{
文本:“与流行的观点相反,Lorem Ipsum并不是简单的随机文本。它起源于公元前45年的一段古典拉丁文学,距今已有2000多年的历史。弗吉尼亚州汉普顿悉尼学院的拉丁语教授理查德·麦克林托克从Lorem Ipsum的一段文字中查到了一个更为晦涩的拉丁语单词“concertetur”在古典文学中对这个词的引用中,发现了无可置疑的来源。Lorem Ipsum来自西塞罗于公元前45年所著的《德菲尼布斯·博诺拉姆和马洛拉姆》(善与恶的极端)的第1.10.32节和第1.10.33节。这本书是一篇关于伦理理论的论文,在文艺复兴时期非常流行。Lorem Ipsum的第一行,“Lorem ipsum dolor sit amet.”来自第1.10.32节中的一行。自1500年代以来使用的Lorem ipsum标准块在下面为感兴趣的人复制。第1.10.32节和第1.10.33节来自“de Finibus Bonorum et Malorum“西塞罗的作品同样以原作形式复制,并附有H.Rackham 1914年翻译的英文版本。”
}
document.write(JSON.stringify(obj).split(/[^\sA-Z]\.(?=\s |[A-Z])/).join(“.“+”

”));
实际上,您可以在一个简单的
replace
方法中使用您的模式,只需使用
$&

替换模式:

your_string.replace(/[^\sA-Z]\.(?=\s|[A-Z])/g, '$&<br><br>')
您的\u字符串。替换(/[^\sA-Z]\。(?=\s |[A-Z])/g,$&


$&
反向引用是指整个匹配值,即
[^\sA-Z]\.
子模式(除空格、大写ASCII字母和点以外的任何字符)使用的值

展示一个你想要输出的例子,这将更容易理解你想要做什么。是的,展示你想要的输入和结果output@Zinc我很抱歉我的英语不好,但是这个聚会“我需要在正确的地方加上新词”不要说我想要的?Tks人工作得很好!抱歉编辑,我看不到
BC.
match,您能帮我修改一下吗@Wiktor Stribiżew
BC.
不匹配,因为
[^\sA-Z]
-在
之前不能有大写字母。也许你想添加允许的缩写?请参阅,
(?:\bBC[sA-Z])\(?=\s[A-Z])
。(请注意,现在regex101中有一个bug,即
$&
backreference不适用于JS风格测试,但实际上它在所有浏览器中都能正常工作。)完美!Tks很多,可能表示一些研究参考正则表达式?没有更多的…tks