Character literals
/a/ Mary had a little lamb. And everywhere that Mary went, the lamb was sure to go.
/Mary/ Mary had a little lamb. And everywhere that Mary went, the lamb was sure to go.
/a/ Mary had a little lamb. And everywhere that Mary went, the lamb was sure to go.
/Mary/ Mary had a little lamb. And everywhere that Mary went, the lamb was sure to go.
"Escaped" characters literals
/.*/ Special characters must be escaped.*
/\.\*/ Special characters must be escaped.*
/.*/ Special characters must be escaped.*
/\.\*/ Special characters must be escaped.*
Positional special characters
/^Mary/ Mary had a little lamb. And everywhere that Mary went, the lamb was sure to go.
/Mary$/ Mary had a little lamb. And everywhere that Mary went, the lamb was sure to go.
/^Mary/ Mary had a little lamb. And everywhere that Mary went, the lamb was sure to go.
/Mary$/ Mary had a little lamb. And everywhere that Mary went, the lamb was sure to go.
The "wildcard" character
/.a/ Mary had a little lamb. And everywhere that Mary went, the lamb was sure to go.
Character classes
/[a-z]a/ Mary had a little lamb. And everywhere that Mary went, the lamb was sure to go.
/[a-z]a/ Mary had a little lamb. And everywhere that Mary went, the lamb was sure to go.
Complement operator
/[^a-z]a/ Mary had a little lamb. And everywhere that Mary went, the lamb was sure to go.
/[^a-z]a/ Mary had a little lamb. And everywhere that Mary went, the lamb was sure to go.
Alternation of patterns
/cat|dog|bird/ The pet store sold cats, dogs, and birds.
/=first|second=/ =first first= # =second second= # =first= # =second=
/(=)(first)|(second)(=)/ =first first= # =second second= # =first= # =second=
/=(first|second)=/ =first first= # =second second= # =first= # =second=
/cat|dog|bird/ The pet store sold cats, dogs, and birds.
/=first|second=/ =first first= # =second second= # =first= # =second=
/(=)(first)|(second)(=)/ =first first= # =second second= # =first= # =second=
/=(first|second)=/ =first first= # =second second= # =first= # =second=
출처 : http://gnosis.cx/publish/programming/regular_expressions.html