in reply to Regex - one and only one / at beginning and end of file path
The benchmark:s!^/*(.*[^/])/*$!/$1/!;
And the results:#!/usr/bin/perl use strict; use warnings; use Benchmark qw /timethese cmpthese/; chomp (our @lines = <DATA>); our (@r1, @r2, @r3); cmpthese -10 => { mikedshelton => '@r1 = map {local $_ = $_; s!^/*!/!; s!/*$!/!; $_} @lines', cchampion => '@r2 = map {local $_ = $_; s{ (?: ^ /* | (?<=[^/])/* $ ) }</>xg +; $_} @lines', abigail => '@r3 = map {local $_ = $_; s!^/*(.*[^/])/*$!/$1/!; $_} @lines', }; die "Unequal\n" unless "@r1" eq "@r2" && "@r2" eq "@r3"; __END__ /foo/bar/baz/ foo/bar/baz/ /foo/bar/baz foo/bar/baz / foo/bar foo
Rate cchampion mikedshelton abigail cchampion 8069/s -- -20% -27% mikedshelton 10038/s 24% -- -9% abigail 11057/s 37% 10% --
Abigail
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Regex - one and only one / at beginning and end of file path
by tachyon (Chancellor) on Dec 15, 2003 at 00:06 UTC | |
by shenme (Priest) on Dec 15, 2003 at 00:19 UTC | |
|
Re^2: Regex - one and only one / at beginning and end of file path
by Aristotle (Chancellor) on Dec 15, 2003 at 04:14 UTC | |
by Abigail-II (Bishop) on Dec 15, 2003 at 09:28 UTC |