我有兩個字符串:檢查子存在於另一個字符串,正則表達式
var first = "913 DE 6D 3T 222"
var second = "913 DE 3T 222"
我要檢查,如果second
存在於first
,最好用regex
。問題是,indexOf
或includes
返回該second
是不出現在first
,這是錯誤的(僅6D
的區別):
first.indexOf(second)
-1
first.includes(second)
false
你是什麼的定義 「包含」 在這裏? –
http://stackoverflow.com/questions/1789945/how-to-check-if-one-string-contains-another-substring-in-javascript – AshBringer
也許你應該拆分你的第二個字符串,並檢查值是否包含在字符串1?第二**不是完全出現在第一,這就是爲什麼這些方法正常工作 – XtremeBaumer