[JavaScript] RegExp In JavaScript
又是 正則表達式,雖然之前有整理一些學習資源,但還是要不斷提醒一下自己;
參考不免俗的還是來一下:http://blog.roodo.com/rocksaying/archives/2670695.html (石頭哥)
最近使用的工具:http://www.radsoftware.com.au/regexdesigner/
下載:Rad.RegexDesigner.Setup.1.4.exe.zip
這邊弄個練習提醒自己
受測文字:txt=”台北101大樓有101層樓”
| 方法 | re | 語法 | 結果 | |
| 1 | test() | /\d/g | re.test(txt) | true | 
| 2 | test() | /\d/ | re.test(txt) | true | 
| 3 | test() | /^\d$/ | re.test(txt) | false | 
| 4 | exec() | /\d/g | re.exect(txt) | 1 | 
| 5 | exec() | /\d/ | re.exect(txt) | 1 | 
| 6 | exec() | /^/d$/ | re.exect(txt) | null | 
| 7 | match() | /\d/g | txt.match(re) | 1,0,1,1,0,1 | 
| 8 | match() | /\d/ | txt.match(re) | 1 | 
| 9 | match() | /^\d$/ | txt.match(re) | null | 
| 10 | replace() | /\d/g | txt.replace(re,’x’) | 台北xxx大樓有xxx層樓 | 
| 11 | replace() | /\d/ | txt.replace(re,’x’) | 台北x01大樓有101層樓 | 
| 12 | replace() | /^\d$/ | txt.replace(re,’x’) | 台北101大樓有101層樓 | 
三小俠 小弟獻醜,歡迎指教