Forum Moderators: coopster
Perl [perl.com]
(my $number) = $string =~ m [perldoc.com]!(\d+)!;
PHP [php.net]
preg_match [php.net]('{(\d+)}', $string, $m);
$number = $m[1];
Andreas
preg_match [php.net](["']pattern["'], $string, $matches);
where the syntax for pattern is as follows:
pattern := delimiter regular_expression delimiter pattern_modifier
/Aaron/i
{Aaron}e
!Aaron!
§Aaron§
'Aaron'
all are valid patterns. Using the slash as a delimiter is not a good idea if you have any slashes in your pattern since those would have to be escaped. To match [domain.tld...] you could use either
/http:\/\/www\.domain\.tld\//
or
!http://www\.domain\.tld/!
The matching engine treats the first character of the pattern as the delimiter. If it has a corresponding character like brackets and braces do then the end delimiter is that corresponding character. Otherwise you simply repeat the delimiter. Everything after the closing delimiter is considered a pattern modifier.
Using curly braces has the advantage that your favorite editor will highlight matching pairs which is quite useful for longer expressions.
Andreas