[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Substitution



Why use a regular expression what's wrong with doing it directly with index?

The trade off is between the explicit operations vs. the avoidance of
the regular expression engine and the byte shuffling.

<chaim>

>>>>> "JB" == Juanma Barranquero <barranquero@laley-actualidad.es> writes:

JB> Thanks everybody for your proposed solutions. I've tested three: two
JB> from Dirk Myers and another by Todd Larason. 

JB> Other solutions didn't work because I didn't explain the problem
JB> clearly enough. In fact, I shouldn't have mentioned that

JB> $s1 = $pat . $s2;

JB> because that's not always true. What *is* true is that $s1 always
JB> *contains* $pat and $s2. Because of that I had to modify Todd
JB> Larason's answer, and Michael Budash's solution is rendered invalid.
JB> Sorry.

JB> All three are much much better than my version, and very fast. I've
JB> tested them with

JB> my $txt = "estabamos alla, y habia un monton de gente y no " .
JB>           "cabiamos, asi que nos fuimos a un cabaret; luego " .
JB>           "un cabo de la guardia civil nos detuvo y nos hizo " .
JB>           "trabajar.";
JB> my $pat = "ab";
JB> my $s2 = "*1";
JB> my $s1 = $pat . " ($s2)";

JB> and also with real data. I've changed Dirk Myer's first version (the
JB> one posted on FWP) to switch the order of the data in the array. I
JB> also modified all versions to quotemeta the search part of the regexp
JB> because it can contain regexp metacharacters (parentheses and dots are
JB> common).

-- 
Chaim Frenkel					     Nonlinear Knowledge, Inc.
chaimf@pobox.com				               +1-718-236-0183

==== Want to unsubscribe from this list? (Don't you love us anymore?)
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org