regex - How to write a regular expression to get text inside XML tags? -
i trying write regular expression return text inside xml tags. instance if had file format
<name>joe blog</name> <email>abc@sample.com</email> <address>123 sample st</address>
how extract text address field?
any appreciated. thanks,
this expression capture address value
<address>(.*?)<\/address>
and place first capture group
example
sample text
<name>joe blog</name> <email>abc@sample.com</email> <address>123 sample st</address>
matches
[0][0] = <address>123 sample st</address> [0][1] = 123 sample st
however
most langages have html parsing tool, example in php using:
$dom = new domdocument(); $dom->loadhtml($your_html_here); $addresses= $dom->getelementsbytagname('address'); foreach($addresses $address) { $address = $address->innertext; // }
Comments
Post a Comment