Home > Archive > PERL Beginners > May 2004 > regexp
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Graf Laszlo 2004-05-19, 12:30 pm |
| Hi
I have the following HTML structure:
<sm:a>
<sm:b>
BBB
</sm:b>
<sm:c>
CCC
</sm:c>
</sm:a>
Every line in this structure is an element of an array,
named @lines, and I access the elements using a foreach loop.
When I know the tag's name, by example 'sm:a',
and I need to extract the information contained by '<sm:a>'
and '</sm:a>' pair and the tags too, how should I proceed ?
I tried a regexp like this:
foreach $s (@lines) {
print "$s";
if($s =~ m|^(<sm:a>\\n)(.*?)(\\n<\/sm:a> )$|s){
($l,$c,$r) = ($1,$2,$3);
print "OK\n";
print "l: '$l'\n";
print "c: '$c'\n";
print "r: '$r'\n";
}else{
print "HEHE\n";
}
}
Help me. Thank you.
| |
| Jupiterhost.Net 2004-05-19, 1:30 pm |
| Graf Laszlo wrote:
> Hi
Hello,
> I have the following HTML structure:
>
Looks more like XML...
> <sm:a>
> <sm:b>
> BBB
> </sm:b>
> <sm:c>
> CCC
> </sm:c>
> </sm:a>
>
> Every line in this structure is an element of an array,
> named @lines, and I access the elements using a foreach loop.
>
> When I know the tag's name, by example 'sm:a',
> and I need to extract the information contained by '<sm:a>'
> and '</sm:a>' pair and the tags too, how should I proceed ?
>
I recommend trying an XML parsing module from search.cpan.org
HTH :)
Lee.M - JupiterHost.Net
| |
| James Edward Gray II 2004-05-19, 1:30 pm |
| On May 19, 2004, at 9:52 AM, Graf Laszlo wrote:
> Hi
> I have the following HTML structure:
>
> <sm:a>
> <sm:b>
> BBB
> </sm:b>
> <sm:c>
> CCC
> </sm:c>
> </sm:a>
>
> Every line in this structure is an element of an array,
> named @lines, and I access the elements using a foreach loop.
>
> When I know the tag's name, by example 'sm:a',
> and I need to extract the information contained by '<sm:a>'
> and '</sm:a>' pair and the tags too, how should I proceed ?
Not totally sure I understand, but let's see if this gets you going:
my $tags = join '', @lines;
print "$1\n" if $tags =~ m/<sm:a>(.*?)<\/sm:a>/s;
Hope that helps.
James
|
|
|
|
|