Please tell me how is the matching done?
The m#/([^/]+)$# matches a string of one or more non-slash characters at the end of a single-line string. (1) One or more is implied by +. (2) non-slash is implied by [^/]. (3) at the end of the string is implied by $. So when you feed the regex with $dir = "/exp/01jehandel/userinput/runwhennewfile", it matches runwhennewfile as you said.
Also what difference does putting brackets '()' for $thisj in its assignment statement makes?
The '()' capture the enclosed regex piece into the first group, $1. As a list assignment is being done, in ($thisj) = $dir =~ ..., that means the matching groups are returned to the left side value. But there's only one group here and $thisj will get its contents.
what is '#' doing here?
As the regex uses literal slashes (/), another delimiter was chosen (in the case, #). That what means m# ... #. Otherwise, it should have been written as /\/([^\/]+)$/ (which is hard to read).
You may learn more at perlretut and perlre.
In reply to Re: Perl Regular Exp
by ferreira
in thread Perl Regular Exp
by Nalina
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |