下面是我必須匹配的字符串如何匹配字符串中包含javascript的動態組件
明天的天氣將比雲更多。 80以上的高點和30中的低點。 明天的天氣將比雲更多。 40年代中期爲高點,70年代爲低點。 明天的天氣比雲更多。在低50年代的高點和低點高80
我以下嘗試:
var str = "The weather tomorrow will be more sun than clouds. Highs in the low 50s and lows in the high 80s";
var regEx = new RegExp("The weather tomorrow will be more sun than clouds. Highs in the "+/{high|low|mid}$/+/^[0-9]{2}$/+"s and lows in the "+/{high|low|mid}$/+/^[0-9]{2}$/+"s.");
if(str.match(regEx)){
console.log("matched");
}else{
console.log("not matched");
}
但是我總是「不匹配」的響應
難道你不能把模式寫成單一模式嗎? ['var regEx = /明天的天氣將比雲彩更加陽光\。 (上|高|低] [0-9] {2}?的高點?並且在(high | low | mid)[0-9] {2} s?\ ./;'](https://regex101.com/r/vHwkJR/1)中處於低位您是否需要使用正則表達式連接字符串對象源模式?請注意,您必須匹配單詞之間的空格,並使's'成爲可選項,因爲它不在任何地方,並且其中一個組不包含'upper'值。 –
謝謝你這是工作 – ewanthak