- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要将以驼峰命名法书写的字母数字字符串转换为常规字符串。我的输入可以是以下任何一个字符串:
var strs = {
input: [
"thisStringIsGood",
"somethingLikeThis",
"a123CapsHere345AndHEREButNOT678Here90End",
"123CapsHere345AndHEREButNOT678Here90e",
"ABCAcryonym",
"xmlHTTPRequest",
"thisDeviceHasA3PrintingService"
],
expectedResult: [
"This String Is Good",
"Something Like This",
"A123 Caps Here345 And HERE But NOT678 Here90 End",
"123 Caps Here345 And HERE But NOT678 Here90 e",
"ABC Acryoynm",
"Xml HTTP Request",
"This Device Has A3 Printing Service"
]
};
在将字符串转换为预期格式后,我正在这样做:
function capSplit(str) {
return str.replace(/(^[a-z]+)|[0-9]+|[A-Z][a-z]+|[A-Z]+(?=[A-Z][a-z]|[0-9])/g, function (match, first) {
if (first) match = match[0].toUpperCase() + match.substr(1);
return match + ' ';
})
}
但问题是空格也与数字相加。我需要将字符串 "thisDeviceHasA3Service"
转换为 "This Device Has A3 Printing Service"
但函数 capSplit(str)
给了我This Device Has A 3 Printing Service
我不知道我错过了什么。这是 fiddle
最佳答案
这是我找到的解决方案:
function capSplit(str) {
return str.replace(/([A-Z][a-z])|([a-z][A-Z])|(\d[a-zA-Z])/g, function (g, m1, m2, m3) {
return m1 ? " " + m1 : (m2 ? m2[0] + " " + m2[1] : m3[0] + " " + m3[1]);
}).replace(/^[a-z]/g, function (g) {
return g.toUpperCase();
});
}
主正则表达式匹配每一种需要插入空格的情况,然后函数在需要的地方插入空格
关于javascript - 正则表达式 : Convert a numeric string from camelCase to regular,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32688495/
我正在使用 Swift 开发一个项目,当时我正在使用 Storyboard为 iPad 和 iPhone 创建 UI,因此我同时需要更改 Storyboard的大小(我使用的是大小类)。在我为 iPh
此示例数据由 Web 服务返回 200,6, "California, USA" 我想使用 split(",") 拆分它们并尝试使用简单的代码查看结果。 String loc = "200,6,\"C
我正在尝试创建正则表达式,以便我可以使用 LucidWorks 对我网站上的某些 URL 进行爬网和索引。 示例网址:http://www.example.com/reviews/assassins-
在检查给定语言是否正常时,我有点困惑。 假设我们必须检查是否: L. The language accepting even number of 0's in regular or not? 我们知道
我真的是新手,所以我为这里的笨拙而道歉。 构造识别以下语言的Deterministic Finite Automaton DFA: L= { w : w has at least two a's an
Pumping Lemma被用来证明一种不规则的语言。但是语言如何 证明是正常的?尤其是, Let L be a language. Define half(L) to be { x | for s
我刚刚开始阅读有关泵送引理的内容,并且知道如何进行一些证明,主要是通过反证法。我似乎找不到答案,只是这个特殊问题。我不知道如何开始。我可以假设必须有一个泵浦长度 P 并且对于 L 的所有 w 元素,L
如果语言 L1,...,Ln 是正则的,那么它们的并集也是正则的吗? 我们知道两种正则语言的并集是正则语言。如何证明多个正则语言的并集也是正则的? 最佳答案 您可以使用归纳法。这是一个非常非常生锈的证
如果对于其语言中的任何字符串 w,PDA(Pushdown Automaton)最多转动其堆栈的方向 k 次,则称其为 k 转。众所周知,语言 L 是线性的当且仅当被 1 圈 PDA 接受。现在,常规
如果语言 L1,...,Ln 是正则的,那么它们的并集也是正则的吗? 我们知道两种正则语言的并集是正则语言。如何证明多个正则语言的并集也是正则的? 最佳答案 您可以使用归纳法。这是一个非常非常生锈的证
给 R 常规语言。 下面的语言是否也是正则的: Comp(R) = { u | u is NOT a sub-word of a word in R } 看起来 Comp(R) 中没有单词,因为 R
设 L1 和 L2 是字母表 {a,b} 上的常规语言。我们定义语言 L3 如下: L3 = {pqr | pr ∈ L1, q ∈ L2} L3 是通过将来自L2 的字符串插入来自L1 的字符串而获
我们都知道(a + b)*是仅包含符号的常规语言 a和 b . 但是(a + b)*是一个无限长的字符串,它是有规律的,因为我们可以建立一个有限自动机,所以它应该是有限的。 任何人都可以解释一下吗?
如何计算常规语言的最小抽水长度。例如,如果我有 0001*,那么最小抽气长度应该是 4,即 000 无法抽气。为什么会这样? 最佳答案 它将小于或等于该语言的最小 DFA 中的状态数减去一。因此,将正
我有以下代码可以执行我想要的操作,从该命令的结果中检索包名称: 命令: dpkg --get-selections | grep amule 要分析的字符串: string = 'amule\t\t\
1、什么是正则表达式? 简单的说:正则表达式(Regular Expression)是一种处理字符串匹配的语言; 正则表达式描述了一种字符串匹配的模式,可以用来检查一个字符串是否含有某种子串,
前言 正则表达式是烦琐的,但是强大的,学会之后的应用会让你除了提高效率外,会给你带来绝对的成就感。只要认真去阅读这些资料,加上应用的时候进行一定的参考,掌握正则表达式不是问题。 1. 引子
给定 L1 上下文无关的非正则语言。 给定 L2 常规语言。 L1 U L2 =常规语言有可能吗? 另外,L1*L2 = 常规语言有可能吗? 我认为第二个是不可能的。但我不确定。 如果上述陈述之一(或
我需要解决抽奖引理问题。 L = { {a,b,c}* | #a(L) N个字母。 pigeon principle告诉我们必须存在一个达到2次的状态,因此在该状态下将存在一个循环。 用您的符号,您
我知道 n > 0 的 anbn 不是抽引引理的规则,但我可以想象 a*b*是常规的,因为 a,b 不必是相同的长度。有没有证据证明它是正常的? 最佳答案 回答你的问题: imagine a*b* t
我是一名优秀的程序员,十分优秀!