toolic hit the nail on the head, but you might choose a different delimiter so that it wouldn't be necessary to escape the forward slash, like this:
my $thing = 'foo/bar/goo'; ( my $stuff ) = ( $thing =~ m{ # Quote-like characters are now {}. ^ # Match at the start of the string. ( [^/]+ ) # Capture everything in the set of all # characters that are not '/' }x # Close the regexp. x modifier allows # freeform (as in non-significant # whitespace). ); print "$stuff\n";
The m{} brackets avoid the leaning toothpick syndrome in the original regexp. Of course if you were matching against a curly bracket the curly brackets wouldn't be all that wonderful as quote delimiters, but for this regexp they work out well. /x modifier added to allow comments and insignificant whitespace (it makes everything prettier).
Dave
In reply to Re: Regex to get everything before first /
by davido
in thread Regex to get everything before first /
by limzz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |