vitoco has asked for the wisdom of the Perl Monks concerning the following question:
I want to know which of the following regexps to remove spaces around commas is more efficient:
$text =~ s/\s+,\s+|\s+,|,\s+/,/g; $text =~ s/\s*,\s*/,/g;
Common sense (not Common::Sense) tells me that the first one should be faster on large texts with more commas than spaces, because less replaces would be done, but I don't know how to measure that.
Hints?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Comparing Regular Expressions
by toolic (Bishop) on Aug 31, 2009 at 21:40 UTC | |
|
Re: Comparing Regular Expressions
by JavaFan (Canon) on Sep 01, 2009 at 00:39 UTC | |
|
Re: Comparing Regular Expressions
by ig (Vicar) on Aug 31, 2009 at 21:54 UTC | |
|
Re: Comparing Regular Expressions
by hexcoder (Curate) on Aug 31, 2009 at 21:46 UTC | |
|
Re: Comparing Regular Expressions
by Anonymous Monk on Aug 31, 2009 at 21:59 UTC | |
by vitoco (Hermit) on Sep 01, 2009 at 14:50 UTC | |
|
Re: Comparing Regular Expressions
by vitoco (Hermit) on Sep 01, 2009 at 15:44 UTC | |
by JavaFan (Canon) on Sep 01, 2009 at 15:55 UTC | |
by vitoco (Hermit) on Sep 01, 2009 at 16:37 UTC | |
|
Re: Comparing Regular Expressions
by Sewi (Friar) on Aug 31, 2009 at 21:51 UTC | |
by JavaFan (Canon) on Sep 01, 2009 at 00:31 UTC | |
by Sewi (Friar) on Sep 01, 2009 at 07:13 UTC |