組成 Regular Expression 的元素及所代表的意義如下 :
由普通字元所組成的 Regular Expression 其意義與原字串字 面意義相同. 例如 :
Regexp `` [0-9]'' 等於 Regexp `` [0123456789]'' 用以表示任意 "一個" 阿拉伯數字. 同理 Regexp `` [A-Z]'' 用以表示任意 "一個" 大寫英文字母.
但應留心 :
故 Regexp `` T[0-9]*\.c''可用以表示 ``T.c''、``T0.c''、 ``T1.c''、``T2.c''、...、``T9.c''、``T00.c''、``T01.c''、``T02.c''、...、 ``T09.c''、``T10.c''、...``T99.c''、``T000.c''、...
資料 ``One is red, and the other is white.'' 中
字串 ``One'', ``is'', ``red'', ``and'', ``the'', ``other'',
``is'', ``white'' 便是所謂的 "字(word)". 而該資料列中,
合於 Regexp ``[Tt]he''的字串如下(粗體字標示)
``One is red, and the other is white.''
合於 Regexp `` \<[Tt]he\>''卻僅有(粗體字標示)
``One is red, and the other is white.''
因同時使用`` \<''及`` \>''
限制合於 Regexp `` [Tt]he''的字串, 必須緊接於字首及字尾之間;
故 ``other''中的子字串 ``the''並不合於這個 Regular Expression.
Regexp `` \([a-z]\)\1''
Regexp `` \(.\)\(.\)\(.\)w\3\2\1" Regexp中`` .''表示任意一個字元. 因字元``w''之前出現的三個字元並無 任何限制, 故可用 `` ...''表之. 但每個`` .''分別用 `` \('',`` \)'' 括住, 之後便可使用 `` \1'', `` \2'', `` \3'' 分別代表將來實際匹配到的前三個字元.