Regex which matches URN by rfc8141
问题 I am struggling to find a Regex which could match a URN as described in rfc8141. I have tried this one: \A(?i:urn:(?!urn:)(?<nid>[a-z0-9][a-z0-9-]{1,31}):(?<nss>(?:[a-z0-9()+,-.:=@;$_!*']|%[0-9a-f]{2})+))\z but this one only matches the first part of the URN without the components. For example lets say we have the corresponding URN: urn:example:a123,0%7C00~&z456/789?+abc?=xyz#12/3 We should match the following groups: NID - example NSS - a123,0%7C00~&z456/789 (from the last ':' tll we match '