What I really want to do is to match all namespace prefixes both for tags and attributes by using a 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 I want is to extract only the following prefixes: foo, baz, bad, bae, bar
I cannot find a regular expression for implementing this.
Please take account that the regular expression should not have hardcoded the names foo, baz, bad, bae, bar...
Something like this?
[<]([^:]+)
will put the prefix (after the angle bracket and before the colon) into group 1.
I see that I misinterpreted the question, after looking more closely.
[<](((\w+):\w+)(\s+(\w+):\w+="\d+"\s*[\/])?)>
which will have a result in groups $3 and possibly $5. I think this will do it.
Whoops, missed a ?
[<](((\w+):\w+)(\s+(\w+):\w+="\d+"\s*[\/]?)?)>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With