我需要兩個正則表達式,以匹配任何以10PL
即(a single whitespace) (any integer) (the string PL in caps) (line terminates)
結尾的內容。我嘗試了以下但他們都沒有工作。例如。給定模式的正則表達式?
var str="Visit W3Schools 45PL"; // should match this
var str1="Visit W3Schools 45PL Other"; // should NOT match this
var str2 = "Any Random value 133PL" // should match this
var str3 = "Any Random value 133Pl" // should NOT match this
另一個應該匹配21.323X230
(a single whitespace) (any floating value) (the word X in caps) (any other floating point value) (line terminates)
。例如。
var test="Visit W3Schools 4X5"; // should match this
var test1="Visit W3Schools 4X5PL Other"; // should NOT match this
var test2 = "Any Random value 13.270X46.96" // should match this
var test3 = "Any Random value 13.21X12.36 " // should NOT match this, as last word is white space
我嘗試了以下模式(第一個(PL一)))。
var patt1=/\s+\d+/PL/g;
var patt2 = /[ ]+[0-9]+/PL/g;
document.write(patt1.test(str));
document.write(patt2.test(str));
document.write(patt1.test(str1));
document.write(patt2.test(str1));
document.write(patt1.test(str2));
document.write(patt2.test(str2));
document.write(patt1.test(str3));
document.write(patt2.test(str3));
結果全爲空(document.write沒有寫任何東西)。那麼,有誰能幫我弄清楚這兩種模式的正則表達式嗎?
[這可能是有幫助的(http://www.regular-expressions.info/javascriptexample.html) – steveax