>>>>> "RN" == Ranga Nathan <[EMAIL PROTECTED]> writes:
others told you that this will be hard with a regex.
RN> 02 s1n1 s1n2 3 s2n1 s2n2 s2n3 1 s3n1 4 s4n1 s4n2 s4n3 s4n4
RN> 02 is the count and I need to extract s1n1 and s2n2
RN> 3 is the count and I need to extract s2n1, s2n2 and s2n3
RN> So I tried to do: $var =
RN> /(.*?)\s+((?:.*?\s+){\1})(.*?)\s+((?:.*?\s+){\3})(.*?)\s+((?:.*?\s+){\5}
RN> )/;
RN> And was expecting "02" "s1n1 s1n2 " "3" "s2n1 s2n2 s2n3 " "1"
RN> "s3n1 " "4" "s4n1 s4n2 s4n3 s4n4 " as matches.
RN> This does not work. The \1, \2 etc are not evaluated as
RN> 'iterators'. I tried the experimental ?{} too.
that is the problem. \1 is only used as part of the actual match text,
not as meta info which the {} quantifier is. the problem is that the
meta stuff needs to be compiled before it can be used but \1 isn't set
until it runs. i don't know the ?{} well enough to help but you should
try usenet and ask some of those who know that feature.
are all the counts pure digit strings and do all the fields have
non-digits? if so, you can skip the quanitifer approach and just match a
digit string followed by strings which have non-digits (using negative
lookahead).
uri
--
Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm