Problem on understanding the regexp command

Hi all,

I'm not clear of this regexp command:

regexp {(\S+)\/[^\/]+$} $String match GetString

From my observation and testing,
if $String is abc/def/gh

$GetString will be abc/def

I don't understand how the /gh in $String got eliminated.
Please help. Thanks

I ran this regex in PERL to show you what exactly is happening:-

#!/usr/bin/perl

my $str = 'abc/def/gh';
my @r_1 = $str =~ /(\S+)\//;
my @r_2 = $str =~ /\/(\S+)/;
print "String: ", $str, "\nRegex 1: ", @r_1, "\nRegex 2: ", @r_2, "\n";
./regex.pl
String: abc/def/gh
Regex 1: abc/def
Regex 2: def/gh

In 1st regex, the string is getting split considering last / sign.
In 2nd regex, the string is getting split considering first / sign.
So basically whatever is there before the first & last / is getting omitted. I hope you understood.

Thanks bipinajith for helping..
There are slight differences between perl and tcl's regex function in this case. Nevertheless, thanks to your sharing, I think I've figured out the meaning of this tcl's regex function code:

regexp {(\S+)\/[^\/]+$} $String match GetString

Here's what I figured out:

The first bracket (\S+), means to search for characters or numbers or symbols except whitespaces (spacebar or tab). This means that at this phase, the searched pattern is abc/def/gh.

The next phase \/[^\/]+$ is to search for the last / plus one or more characters or numbers or symbols except the / symbol till the end of the string. Only the matched pattern inside the ( ) will be copied to GetString which means in this case abc/def

This is what I found out, please comment if I'm wrong.