regex - How can I match namespace prefixes with regular expression -


what want match namespace prefixes both tags , attributes using regular expression.

for example:

<foo:person bar:id="43">   text text <nomatch:free text   <baz:name>     text nomatch:free> text   </baz:name>     text nomatch:free="44" text     <age bae:years="44" />     text </foo:person> 

what want extract following prefixes: foo, baz, bad, bae, bar

i cannot find regular expression implementing this.

please take account regular expression should not have hardcoded names foo, baz, bad, bae, bar...

something this?

[<]([^:]+) 

will put prefix (after angle bracket , before colon) group 1.

i see misinterpreted question, after looking more closely.

[<](((\w+):\w+)(\s+(\w+):\w+="\d+"\s*[\/])?)> 

which have result in groups $3 , possibly $5. think it.

whoops, missed ?

 [<](((\w+):\w+)(\s+(\w+):\w+="\d+"\s*[\/]?)?)> 

Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -