Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Ruby Programming
Previous Page Home Next Page


Every regular expression contains a pattern, which is used to match the regular expression against a string.

Within a pattern, all characters except ., |, (, ), [, {, +, \, ^, $, *, and ? match themselves.

showRE('kangaroo', /angar/) k<<angar>>oo
showRE('!@%&-_=+', /%&/) !@<<%&>>-_=+

If you want to match one of these special characters literally, precede it with a backslash. This explains part of the pattern we used to split the song line, /\s*\|\s*/. The \| means ``match a vertical bar.'' Without the backslash, the ``|'' would have meant alternation (which we'll describe later).

showRE('yes | no', /\|/) yes <<|>> no
showRE('yes (no)', /\(no\)/) yes <<(no)>>
showRE('are you sure?', /e\?/) are you sur<<e?>>

A backslash followed by an alphanumeric character is used to introduce a special match construct, which we'll cover later. In addition, a regular expression may contain #{...} expression substitutions.
Ruby Programming
Previous Page Home Next Page

  Published under the terms of the Open Publication License Design by Interspire