So, in this case, Perl captures what it finds between the [ and ] and stores that string in $1.
And what does it match? In this case, we've told it to match any character ("."), repeated 0 or more times ("*"), in a non-greedy manner ("?"). This last is best illustrated by example. Say your original string was
There are two sets of [ and ] strings in there. Without the "?" in the regular expression, Perl would match from the first [ to the last ], putting the following into $1:aslkj[2099asgjskjw]asljgn[awoeiwj]
Most likely, this isn't what you want, so we put in the non-greedy modifier to make Perl do what you want. :)2099asgjskjw]asljgn[awoeiwj
By the way, I said that "." matches any character; this isn't strictly true. It usually doesn't match carriage returns; if you want it to match carriage returns, add the "/s" modifier at the end of the regular expression.
For more information, take a look at perlre. It explains all of this and more.
In reply to Re: how do i take out a string within a string ?
by btrott
in thread How to extract a delimited substring?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |