|
Posted by Rik on 06/06/06 16:15
greatprovider wrote:
> hah...that was the trick...thank you all...
>
> one last question...now would anyone mind explaining me how "$1"
> works?
In a regular expression, you can "capture" pieces that match a pattern with
(). The number after the $ indicates which piece, captures are numbered from
the first opening '('.
For instance:
**567HJK
'/((\*{2})(\d+))/'
$1 will contain the match: '**567';
$2 will contain the match: '**';
$3 will contain the match: '567';
Normally, pieces that have to match a certain regex, but aren't used any
further, don't need (). In some cases, it's necessary for the pattern. In
that case, you could just use the numbered matches you need, discarding the
others (with multiple captures in a regex, it is absolutely not necessary to
use them all). To keep a complex regex more clear, you could also make a
'non-capturing' group by adding ?: after the opening. For instance:
(?:\s+(\d+)) will capture the digits in $1, instead of $2, because the first
parenthesis is told not to capture anything.
Want to learn more about regexes?
http://www.regular-expressions.info/tutorialcnt.html was a big help for me.
Grtz,
--
Rik Wasmus
[Back to original message]
|