Re: regex assistance
by Hugo van der Sanden at 13:32 10/06/07 (Forum::Technical Advice::General)
The trouble with examples is that there are so many ways to read them.

It could be: get the chunk of text inside each <tag>...</tag>. Split the chunks into two lists, those before and those after the literal text 'tum-te-tum-te-tum'.

Or it could be: get the (exactly) 5 chunks of text in <tag>...</tag>, and put 3 in one array and 2 in another.

Or many other things, perhaps involving 'blah' and 'foo' and 'bar'.

I don't know PHP, but in perl I probably wouldn't try to extract the info for the first of those definitions in one pattern, but something like:

my($head, $tail) = split $text, m{tum-te-tum-te-tum}, 2;
my @array1 = ($head =~ m{<tag>(.*?)</tag>}g);
my @array2 = ($tail =~ m{<tag>(.*?)</tag>}g);

In general though, coming up with a clear definition of what you need to match is about 90% of the work in writing the code. The other 10% is effectively a translation exercise.

Hugo

<< scp, sftp, etc... Anyone know of a solution to >>
Powered by
Powered by Novacaster