in reply to Regex to get everything before first /
my ($stuff) = $thing =~ m{^([^/]*)};
my ($stuff) = $thing =~ m{^(.*?)/}s;
my ($stuff) = split(qr{/}, $thing, 2);
my ($stuff) = split(qr{/}, $thing);
The second requires the presence of a "/", and uses the non-greedy modifier which I prefer to avoid.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex to get everything before first /
by FunkyMonk (Bishop) on Jun 06, 2011 at 21:11 UTC | |
by ikegami (Patriarch) on Jun 06, 2011 at 22:12 UTC | |
|
Re^2: Regex to get everything before first /
by jwkrahn (Abbot) on Jun 06, 2011 at 22:05 UTC |