[英]javascript : Regular expression for a:b
I am looking for the occurrence of the pattern a:b
. 我正在寻找模式a:b
。 This could be of the form 形式可能是
a: b
or a: b
或 a :b
or a :b
或 a : b
(note the optional spaces). (请注意可选空格)。
I am new to RegExes and was trying something of the form : a\\s:\\sb
but kinda din work.. 我是RegExes的新手,正在尝试某种形式的东西: a\\s:\\sb
但有点工作。
Can somebody point me out the right one ? 有人可以指出我合适的人吗?
Thanks.. 谢谢..
Your current regex is 'a\\s:\\sb'. 您当前的正则表达式为“ a \\ s:\\ sb”。 Since you didn't make the '\\s' part of the pattern optional, this only matches 'a[SPACE]:[SPACE]b', where I am using [SPACE] as a standin for space, tab, or any other whitespace character. 由于您没有将模式的'\\ s'部分设置为可选,因此这仅与'a [SPACE]:[SPACE] b'匹配,在这里我将[SPACE]用作空格,制表符或其他任何内容的替代品空格字符。 Instead, you can use 'a\\s?:\\s?b', which makes the whitespace optional. 相反,您可以使用'a \\ s?:\\ s?b',这使空格成为可选。
For more regular expression information, I would recommend the Perl regular expression tutorial . 有关更多正则表达式的信息,我建议使用Perl正则表达式教程 。
Try a\\s*:\\s*b
. 尝试a\\s*:\\s*b
。 Also, this is handy to test: http://www.pagecolumn.com/tool/regtest.htm 另外,这很容易测试: http : //www.pagecolumn.com/tool/regtest.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.