One final addition to toolic and davido's posts:
You might as well make it match {0,} instead of {1,} so that strings that start with / will equal the empty string instead of undef.
This way you can avoid "Use of uninitialized value in concatenation (.)" warnings.
use warnings; use strict; my $thing = 'foo/bar/goo'; my ($stuff) = $thing =~ m{^([^/]*)}; print "$stuff\n"; __END__ foo
In reply to Re: Regex to get everything before first /
by wind
in thread Regex to get everything before first /
by limzz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |