Most of Ruby's built-in types are similar to other programming languages. Mainly have strings,integers,floats,arrays and so on. However, only the scripting language,
such as Ruby,perl, and awk provide support for built-in expression types. Shame: Regular expressions are a powerful text-processing tool, albeit covert.
They are very different than simply adding an interface class library.
A regular expression is an easy way to match a string with a specified pattern. In Ruby, the typical way to create a regular expression is to write the pattern between two slashes (/pattern/).
After all, Ruby is Ruby, and regular expressions are objects and can be manipulated like objects.
For example, you can use the following regular expression to write a pattern that matches a string containing Perl or Python.
/perl| python/
In the forward slash body, there are two strings that we want to match, separated by (|). This pipe character means "left or right", which is Perl or Python in this pattern.
You can also use parentheses in a pattern, just as you would in an arithmetic expression, so this pattern can also be written as
/p (Erl|ython)/
You can also specify duplicates in the pattern. /ab+c/matches a string with one or more b followed by a C. Replace the + number with the * number, the regular expression created by/ab*c/is
Match a A followed by 0 or more b followed by a C.
You can also match a set of characters in a pattern. The commonly used character type example has \s, it matches a white space character (Space,tab, line break, etc.); \d matches any number;
\w matches any of the typical word characters. a period (.) matches (essentially) any character.
We combine all of these together to make a useful regular expression.
/\d\d:\d\d:\d\d/# A time such as 12:34:56
/perl.*python/# Perl, zero or more other chars, then Python
/perl Pyth on/# Perl, a spaces, and Python
/perl *python/# perl, zero or more spaces, and Python
/perl +python/# perl, one or more spaces, and Python
/perl\s+python/# Perl, whitespace characters, then Python
/ruby (perl| Python)/# Ruby, a space, and either Perl or Python