【问题标题】:How to split a string with camelcase and also with uppercase using regex in javascript? [duplicate]如何在javascript中使用正则表达式用驼峰和大写拆分字符串? [复制]
【发布时间】:2018-11-30 10:08:00
【问题描述】:

这是我的原始字符串:

myCamelCaseSTRINGToSPLIT

预期结果:

my Camel Case STRING To SPLIT

我正在使用的当前正则表达式是

(?=[A-Z])

如有任何帮助,将不胜感激

【问题讨论】:

标签: javascript regex


【解决方案1】:

请使用这个正则表达式。

yourString.replace(/([A-Z]+)/g, " $1").replace(/([A-Z][a-z])/g, " $1")

yourString.replace(/([A-Z]+)/g, " $1")

Live Demo with two times Replace

Live Demo with single time Replace

【讨论】:

  • 第二个 replace 在前几个单词之间添加了几个额外的空格。
  • 查看我的现场演示,您会看到不同之处@thgaskell
猜你喜欢
  • 2021-10-21
  • 1970-01-01
  • 2013-06-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多