当在javascript中获取文本中的,或.时,我想要拆分。
我的短信是这样的:
猫爬上tree.In这句话,$U_SEL{}是个名词。
我要数组为:
1.The cats climbed the tall tree.
2.In this sentence
3.$U_SEL{}
4.is a noun发布于 2016-08-05 12:24:39
这个挑战的正则表达式是。
var text = "The cats climbed the tall tree.In this sentence, $U_SEL{} is a noun."
var regex = /[.,]/;
text.split(regex);有关
regex的更多信息,请访问表达式
发布于 2016-08-05 12:24:55
这是regex。要在{}上拆分,首先将替换为{},或{}.,然后尝试split。
var str = "The cats climbed the tall tree.In this sentence, $U_SEL{} is a noun";
str = str.replace("{}", "{},");
//Array with splitted value
var result = str.split(/[,.]/g);
//Printing the result array
console.log(result);
发布于 2016-08-05 12:26:04
尝尝这个
<script type="text/javascript">
var text = "The cats climbed the tall tree.In this sentence, $U_SEL{}, is a noun";
var spliteds = text.split(/[\.,]/);
alert(spliteds[0]);
alert(spliteds[1]);
alert(spliteds[2]);
alert(spliteds[3]);
</script>https://stackoverflow.com/questions/38789041
复制相似问题