2. In Perl, you can use () around the parts of the RE you want to refer to after the RE matching.
See "man perlre" for details.
ie: $string1 =~ /\/(.*)\//;
$1 now contains wathever was matched in the first pair of () ("backreference").
$2, $3, ... can be used if you use more than one pair of ().
You'll need to use \1, \2, ... instead of $1, $2, ... if you want to refer to the matched items from
within the statement that contains the RE. $1, $2, ... are only intended to be used after that statement
(ie when following statements refer back to the last RE match - hence the term "backreference").
In shell, you may want to use a utility like cut, sed, grep or awk.
cut is probably the easiest (but you can specify only 1 delimiter character):
Code:
echo "$string1" | cut -d'/' -f2
would select "def" from the string "abc/def/ghi".
Maybe shell knows backreferences too. I haven't checked that.