如何在JavaScript中按大写和小写分割字符串?
16lz
2021-01-22
Is it possible to split Strings in JavaScript by case such that the following string below (myString) would be converted into the array (myArray) below:
是否可以用JavaScript分割字符串,以便下面的字符串(myString)将被转换为下面的数组(myArray):
var myString = "HOWtoDOthis";
var myArray = ["HOW", "to", "DO", "this"];
I have tried the regex below, but it only splits for camelCase:
我已经试过下面的regex,但是它只对camelCase进行分割:
.match(/[A-Z]*[^A-Z]+/g);
2 个解决方案
#1
8
([A-Z]+|[a-z]+)
. Match all upper case, or all lower case multiple times in capturing groups. Give this a try here: https://regex101.com/r/bC8gO3/1
([a - z]+ |[a - z]+)。在捕获组中匹配所有大写或小写多次。在这里尝试一下:https://regex101.com/r/bC8gO3/1
更多相关文章
- JSON.parse(xhr.responseText)意外的字符串错误
- JS计算任意字符串宽度
- 使用jackson json将属性添加到json字符串
- ajax请求返回一个空字符串作为响应
- 在Javascript中将带有空格的字符串数组转换为小写,然后在Webkit中
- 返回指定时间段相同间隔数组
- 如何将带有双引号反斜杠的JSON字符串转换为Javascript对象
- JavaScript数组中的唯一计数,按计数排序
- Javascript sort()不适用于Chrome中超过10个对象的数组