Your '\1' question aside:
Your solution requires you to know the number of patterns in the string.
For long strings, a regex could be slow.
Why not just 'split' on whitespace into an array and then use array
indices to easily extract the items you want?




-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
On Behalf Of Ranga Nathan
Sent: Friday, October 11, 2002 1:42 PM
To: [EMAIL PROTECTED]
Subject: [Boston.pm] Calling regex gurus ..A regex question..


I need to parse a string that has multiple occurrences of a pattern that
is determined by an embeded count. For example:

02 s1n1 s1n2 3 s2n1 s2n2 s2n3 1 s3n1 4 s4n1 s4n2 s4n3 s4n4

02 is the count and I need to extract s1n1 and s2n2

3 is the count and  I need to extract s2n1, s2n2 and s2n3

And so on.

So I tried to do:
$var =
/(.*?)\s+((?:.*?\s+){\1})(.*?)\s+((?:.*?\s+){\3})(.*?)\s+((?:.*?\s+){\5}
)/;

And was expecting "02" "s1n1 s1n2 " "3" "s2n1 s2n2 s2n3 " "1" "s3n1 "
"4" "s4n1 s4n2 s4n3 s4n4 " as matches.

This does not work.
The \1, \2 etc are not evaluated as 'iterators'. I tried the
experimental ?{} too.



---Closing information gaps-----
Ranga Nathan, Reliance Technology
>>SEVIS solution now! http://goreliance.com
>>Live demo at http://any2xml.com/docs/timesheet_demo.shtml<<
>>Get free COBOLExplorer at http://goreliance.com/download-products <<

_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm



_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to