Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想添加javascript regexp来满足我的顾虑_Javascript_Regex - Fatal编程技术网

我想添加javascript regexp来满足我的顾虑

我想添加javascript regexp来满足我的顾虑,javascript,regex,Javascript,Regex,我需要以下regexp,例如。。 括号只是用来表示单词的 (abc)=>通过 (abc)=>通过*带有尾随空格的abc (abc..blah..=>通过*.blah。。表示包含空格的任何字符 (abcd)=>失败 有什么好主意吗 我修剪了字符串,使前两个案例基本相同 但是当(abcd)出现时,我不能让它失败使用regex: var doesItPass = (stringToValidate.split(" ")[0] == "abc") ? false : true; /^abc\s*$/

我需要以下regexp,例如。。 括号只是用来表示单词的

(abc)=>通过
(abc)=>通过*带有尾随空格的abc
(abc..blah..=>通过*.blah。。表示包含空格的任何字符
(abcd)=>失败

有什么好主意吗

我修剪了字符串,使前两个案例基本相同

但是当(abcd)出现时,我不能让它失败
使用
regex

var doesItPass = (stringToValidate.split(" ")[0] == "abc") ? false : true;
/^abc\s*$/    

Regex就是做这些事情的方法。

没有不拆分字符串的优雅方法吗?看起来你错过了一个结束语parenthesis@SungsooMoon. 不,开头是一个输入错误。看起来它在“aaa”上有效。当我用/^abc(\s[\w]*|)解决问题时,我也得到了解决$/i@SungsooMoon. 它必须以abc开头,并使用0或更多空格进行编辑?@SungsooMoon。我更新了答案,但请给出问题中的所有细节。
if (/abc\b/im.test(subject)) {
    // Successful match
} else {
    // Match attempt failed
}