[英]How to check if the start of a string has specific character using regex in javascript?
我有一个要求,我必须使用正则表达式检查单词是否有+
后跟空格作为前两个字符。我尝试创建正则表达式并使用match方法,但该方法始终返回null。有人可以建议我如何为正则表达式创建正则表达式以下情况?
getWord: function() {
var index = this.getIndexOfSelectedText(),
words = this.state.editorText.slice(0, index.start),
var selectedWords = words.split('\n').pop();
console.log('selectedWords', selectedWords);
var exp = '/^\+\s/'
console.log(selectedWords.match(exp));
if (selectedWords.match(exp)) {
return true;
}
您可以尝试使用正则表达式^\\+\\s+
...请在此处进行测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.