[英]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.