Avatar of Russ Suter
Russ Suter

asked on 

Regex to match groups in any order

I have the following regular expression:
^\s*<\s*script\s*name\s*=\s*["](?<name>[^"]*)["]\s* platform\s*=\s*["](?<platform>[^"]*)["]\s*(deferred\s*=\s*["](?<deferred>[^"]*)["])?>\s*$

Open in new window

It matches fine against the following:
<script name="FOO" platform="all">
<script name="FOO" platform="all" deferred="yes">
However, I need it to match regardless of the order of the parameters so it should also match:
<script name="FOO" deferred="yes" platform="all">
 -- and --
<script platform="all" deferred="yes" name="FOO">
How do I rewrite the above Regex so that it will match each name-value pair regardless of what order they appear?
Regular ExpressionsC#

Avatar of undefined
Last Comment

8/22/2022 - Mon