I want to match strings with the following template:
<el key1="val1" key2="val2" />
I can match them with a regex such as:
^(<el\s+)(?=.*key1=".*".*)(?=.*key2=".*".*)(.*\/>$)
The problem is that
<el key1="val1" key2="val2" aaa />
<el key1="val1" aa key2="val2" />
<el aaa key1="val1" key2="val2" />
are also matches. I want to find ^<el\s+
exactly at the beginning, (\/>)$
at the end and the two \s+keyn=".*"\s+
somewhere in between.
EDIT:
(based on comments and replies) Keys can be title
, uri
, text
. The issue with the answers so far is the keys can be in any order, so:
<el key1="val1" key2="val2" />
<el key2="val2" key1="val1" />
are both valid.