是否可以使用正则表达式方法给出如下输出结果。
输入:
1. same ; as same ; like this ; such
输出:
same.<br>as same.<br>like this.<br>such.
注意::在space
(点)之后,每个单词之后还有一个.
,在输出结果中还有一个.
(点)放在最后一个单词such.
答案 0 :(得分:0)
const test1 = '134. same ; as same ; like this ; such 2. '
const test2 = '1. same ; as same ; like this ; such 2'
const myReplacedString1 = test1.replace(/ ; /g,'.<br>').replace(/^[\d]+.[\s]*/g,'').replace(/\.?\s+$/g,'') + '.'
const myReplacedString2 = test2.replace(/ ; /g,'.<br>').replace(/^[\d]+.[\s]*/g,'').replace(/\.?\s+$/g,'') + '.'
console.log(myReplacedString1)
console.log('same.<br>as same.<br>like this.<br>such 2.' === myReplacedString1)
console.log(myReplacedString2)
console.log('same.<br>as same.<br>like this.<br>such 2.' === myReplacedString2)