正则

249 阅读1分钟

1、将“/”替换成“-”

string.replace(/\//g,'-')

2、去掉所有的空格和冒号

String.replace(/\s|:/g,””)

3、去掉所有的html标记

String.replace(/<\/?[^>]*>/gim,"")

4、以......结尾

例子:以‘sg’或‘sgd’结尾

console.log("adcsgfedsgd".match(/sg$|sgd$/g));

5、以......开头

console.log("abcd".match(/^a/g))

6、以......开头且以......结尾

console.log("abcd".match(/^a.*d$/g))

7、后台返回回车,转换为

String.replace(/\n/g, "<br/>")