Difference between revisions of "Regexp"
From MohidWiki
m (1 revision) |
(→See also) |
||
Line 16: | Line 16: | ||
*[[Sed]] | *[[Sed]] | ||
*[[Awk]] | *[[Awk]] | ||
+ | *[[Tr]] | ||
*[[Python]] | *[[Python]] | ||
*[[Ruby]] | *[[Ruby]] |
Revision as of 14:18, 27 April 2010
Regexp stands for regular expressions. Regular expressions are what made languages like Awk and Perl notorious. Regular expressions are expressions equating a pattern string. To write a regular expression in Perl on must insert it between slashes (/regexp/)For example:
/[a-z]/
means all the alphabet lowercase letters.
/[0-4]/
stands for all the digits from 0 to 4 inclusive.
/\d{2,5,7}/
stands for all the sequences of 2, 5 or 7 digits.
The interesting thing is that you can compose regexps into complex patterns. For example the regexp
/[A-Z]:[0-3]\.\S{1,8}/
describes a pattern that will match, for example, the strings B:1.HelloSir or 'A:0.Good. But it will not match a:2.darn because the first letter must be uppercase.