Problem:
Given a HTML line, find the tag and its attributes.
ex Name:<input type="text">, here tag is 'input' and attribute is 'type'
ex Name:<input type="text">, here tag is 'input' and attribute is 'type'
Input Format:
included in code
$n='<a href="http://www.google.com" name="test" id="id1">Click me</a>';
Output Format:
Attributes for tag a are href & name & id
Attributes for tag a are href & name & id
Constraints:
none
none
Sample Input
<a href="http://www.google.com" name="test" id="id1">Click me</a>
Sample Output:
Attributes for tag a are href & name & id
Attributes for tag a are href & name & id
Explanations:
tag is a and others are attributes
tag is a and others are attributes
Solution:
($a)=$n=~/<(.*?)\s/;
(@arr)=$n=~/\s(.*?)=/g;
print "attributes of tag $a are ";
$c=0;
foreach(@arr)
{
if($c>0){print "& "};
print "$_ ";
$c++;
}
Tips:
Tag is anything between < and space. attribute is anything between space and =