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

更多相关文章

  1. JSON.parse(xhr.responseText)意外的字符串错误
  2. JS计算任意字符串宽度
  3. 使用jackson json将属性添加到json字符串
  4. ajax请求返回一个空字符串作为响应
  5. 在Javascript中将带有空格的字符串数组转换为小写,然后在Webkit中
  6. 返回指定时间段相同间隔数组
  7. 如何将带有双引号反斜杠的JSON字符串转换为Javascript对象
  8. JavaScript数组中的唯一计数,按计数排序
  9. Javascript sort()不适用于Chrome中超过10个对象的数组

随机推荐

  1. Android学习资料分享
  2. android 去除ScrollVIew拉到尽头时再拉的
  3. Android圆形进度显示控件的SectorProgres
  4. 关于android生命周期那点事
  5. MTK Android Driver :sound
  6. 新添的Activity 要在 manifest 中注册 否
  7. android 设置 源码 修改默认主题为白底黑
  8. [置顶] android 心跳包的分析
  9. Android Permission中英对照
  10. MyEclipse10 配置 Android SDK 时遇到的