Help with a regular expression

Soldato
Joined
1 Mar 2003
Posts
5,508
Location
Cotham, Bristol
I'm wanting to scan through an xml file and store the names of tags I've found in a list

The xml tags take the format

PHP:
<tag:name param1="" param2=""></tag:name>

I'm just wanting to match the first part of the tag i.e. <tag:name

I've tried writing a re pattern which is

PHP:
tag_re = "([<]+)([^?]+)((?:[\s])$)"

But it doesn't return any matches, what have I done wrong?
 
But I don't know what x and y is, as I said I don't want the entire <tag:name param1="" param2=""> just <tag:name
 
Last edited:
OK this is for javascript but what about:
Code:
\b<[a-z]+:\w+\b

so from beginning of line match < then 1 or more lowercase characters, then a : then another word, then the end of the line.

though depending on the language, can't you use the XML xpath to get what you need?
 
Last edited:
Back
Top Bottom