Regexps use elements to instruct the regular expression engine on how to find a given string. : Regexps « Development « Ruby






Regexps use elements to instruct the regular expression engine on how to find a given string.


A combination of the special characters, enclosed by a pair of slashes (//), makes up a regular expression pattern. 


^        Matches the beginning of a line

$        Matches the end of a line

\w       Matches a word character

[...]    Matches any character in the brackets

[^...]   Matches any characters not in the brackets

*        Matches zero or more occurrences of the previous regexp

+        Matches one or more occurrences of the previous regexp

?        Matches zero or one occurrences of the previous regexp

 








Related examples in the same category

1.An example of a regular expression used to match a string with the String method scan.
2.Search for a word from the very beginning
3.Looking for a word
4.grep(/men/)
5.grep(/m[ae]n/)
6.grep(/men|man/)
7.grep(/m(e|a)n/)
8.grep(/^When in/)
9.grep(/outcast state,$/)
10.grep(/\Aen in/)
11.grep(/e n,\z/)
12.grep(/[\(\d\d\d\)]?\d\d\d-\d\d\d\d/)
13.grep(/colou?r/)
14.grep(/[\(\d+\)]?\d+-\d+/)
15.grep(/[\(\d{3}\)]?\d{3}-\d{4}/)
16.Implementing Class and Singleton Methods
17.Match a time
18.Match Perl, zero or more other chars, then Python
19.Match Perl, a space, and Python
20.Match Perl, zero or more spaces, and Python
21.Match Perl, one or more spaces, and Python
22.Match Perl, whitespace characters, then Python
23.Match Ruby, a space, and either Perl or Python
24.Match a regular repression in if statement
25.sub and gsub replace with regular expressions
26.Replace Perl or Python with Ruby
27.The method Regexp#match matches a regular expression against a string.
28.MatchData-related $-variables are in $~