On Mon, 24 Sep 2001, Kenneth Graves wrote:
> Date: Mon, 24 Sep 2001 16:31:39 -0400 (EDT)
> From: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
>
> $s = "regex tesT";
> $s =~ /(.)*/;
> print $1; #prints "T"
>
> i wish $1 could be an array containing ("r", "e", "g", "e", "x", ... ,
> "T") or better yet, a two dementional array @mem = (["r" ... "T"]). i also
> prefer to work with the positions as upposed to the strings themselves as
> it is much less memory intensive. does anyone know a way to store either
> the string or the positions of all text matching a memory slot as upposed
> to just the last piece?
>
> Not entirely sure this is what you want:
>
> $s = "regex tesT";
> @a = $s =~ /(.)/g;
> print "@a\n"; #prints "r e g e x t e s T\n"
hmm, this solves the problem only for the top level though. i have nested
memory. not to mention more than one. here's a simple example problem:
all input conform to this regex: /first: (?:\d+\n)+\nlast: (?:\d+\n)+/
use one regex match and construct a data structure that will allow you
to print out
"first numbers are a1, ... and the last numbers are b1, ... bn"
give my fantacy regex memory scheme i would do this
$text =~ /first: (\d+\n)+\nlast: (\d+\n)+/;
print "first numbers are "
. join (",",@$mem[0]);
print "and the last numbers are".
join (",",@$mem[1]);
this may be to simple. i'm having trouble thinking of other simple
examples. this algorithm is going to be used in my any2xml text
parser. the tag the user types in template will be used to contruct a
regex and then each tag gets passed recursivly the text which in
matched. tags have iterators identical to the regex iterators like
*,+,{1,50}, etc and if a memory repeats, the tag reasponcible for that
part of the regex will get called recursivly a number of times equal to
the number of matches that memory variable made.
> I don't see how /(.)*/ would ever get you want you want, unless you
it won't, as i said. but it would if and only if the perl regex engine
acted in the way i said i wished it did. that being storing $1 as @1 with
everything that a memory with an iterator matched.
> start playing with (?{...}) or similar deep juju. From outside the
> regex, that's only ever going to give you the match for (.) after
> the * finishes being greedy.
>
> --kag
>
>
thanks
-mike