我有这个类型的字符串
str = "\n\t\t\t\t\t\t\t\tRemovable neck strapBelt loop\n \n \n \n\t\t\t\t\t\t\"想要转换成
Removable neck strap Belt loop注意strap,Belt是如何分开的。
到目前为止,我已经做到了
str.gsub(/\n|\t/,'').strip这给了我
Removable neck strapBelt loop 但未能在strapBelt之间分道扬镳。
发布于 2014-03-25 17:12:32
str.gsub(/([a-z])([A-Z])/, '\1 \2').strip发布于 2014-03-25 17:12:10
用这个:
str = str.gsub(/(?<=[a-z])([A-Z])/, ' \\1')在这里,它检查大写字母[A-Z]是否与较小的字母[a-z]完全一致(使用正向后查找(?<=[a-z]))。如果是,则将其替换为空格和大写单词(在\\1中作为捕获组)本身。
https://stackoverflow.com/questions/22641670
复制相似问题