DIV CSS 佈局教程網

菜鳥 JavaScript 基礎整理(三):正則表達式
編輯:JavaScript基礎知識     

RegExp 物件的三大方法

JavaScript 的正則表達式由 RegExp 物件表示,它提供了 test()、exec() 與 compile() 三個方法。

test() 方法

test() 用來檢索字串中是否含有符合的內容,回傳值是 true 或 false。

var patt1 = new RegExp("e");
document.write(patt1.test("The best things in life are free"));

exec() 方法

exec() 同樣用於檢索字串中的指定值,但回傳的是被找到的內容;若沒有符合的結果,則回傳 null。

var patt1 = new RegExp("e");
document.write(patt1.exec("The best things in life are free"));

(本篇先整理到此,後續再補充 compile() 的用法。)

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved