Special_K has asked for the wisdom of the Perl Monks concerning the following question:
Suppose I have the following in a text file "fbb_test":
/foo/bar/baz
Now suppose I have the following script:
#!/tool/bin/perl -w use strict; my $file = "/tmp/fbb_test"; open(FILE, $file) || die("ERROR: Unable to open $file for read, exitin +g...\n"); while (<FILE>) { chomp($_); if ($_ =~ /\/(.+?)$/) { printf("captured $1\n"); } } close(FILE);
The script is returning "captured foo/bar/baz". Given that I specified the non-greedy operator (?), I would have expected the result to be "baz", as the non-greedy operator would have matched as few characters as possible between a forward slash and the end of the line. What am I missing here?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why does this non-greedy match not work?
by Fletch (Bishop) on Jun 29, 2020 at 17:41 UTC | |
by haukex (Archbishop) on Jun 29, 2020 at 19:07 UTC | |
|
Re: Why does this non-greedy match not work?
by roho (Bishop) on Jun 30, 2020 at 10:22 UTC |