Regular Expression 是用來當作字串搜尋的 pattern。
常搭配 String.prototype.replace()
及 String.prototype.search()
使用。
基本語法
/pattern/modifiers
常見的 modifiers
i
: 會忽略大小寫。g
: 搜尋所有符合的字串,不限於第一個找到的。
modifiers 可以同時使用,如:/pattern/ig
。
常見的 pattern
[abc]: 搜尋符合 abc 的字串
[^abc]: 搜尋 abc 以外的字串
[0-9]: 搜尋符合數字 0-9 的字串
[a-z]: 搜尋符合 a-z 的字串