[英]Javascript Regex for colon?
I'm wondering how I can use javascript regex to match a word like: 我想知道如何使用javascript正则表达式匹配一个单词,如:
Name:
with all variations of spaces ? 有各种空间变化? This is where I'm getting stuck.
这是我陷入困境的地方。 ie
即
Name<space>: Fred
Name:<space>Fred
or Name<space>:<space>Fred
Name:<space>Fred
或Name<space>:<space>Fred
Note the positioning of the spaces after the name, after the colon etc ? 注意名称后面的空格位置,冒号后面等等?
I was hoping something like /(name(\\s*:\\s*)?)\\w/g
would work but it doesn't :( 我希望像
/(name(\\s*:\\s*)?)\\w/g
可以工作,但它不会:(
Name starts with a capital letter. 名称以大写字母开头。 The regex should also match name starting with a capital N.
正则表达式还应匹配以大写字母N开头的名称。
i
flag at the end. i
标志。 The *
means 0 or more. *
表示0或更多。 The ?
的
?
is not needed anymore. 不再需要了。
Something like this should work 这样的事情应该有效
/Name\s*:\s*\w*/g //matches "Name"
/[Nn]ame\s*:\s*\w*/g //matches "Name" or "name"
/name\s*:\s*\w*/gi //the entire regex is case insensitive
正则表达式/name\\s*:\\s*\\w/gi
就足够了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.