Skip to content

Instantly share code, notes, and snippets.

@jhorsman
Last active December 8, 2016 12:35
Show Gist options
  • Save jhorsman/57f359efee6df50491209c5bcc6ebba1 to your computer and use it in GitHub Desktop.
Save jhorsman/57f359efee6df50491209c5bcc6ebba1 to your computer and use it in GitHub Desktop.
SDL DXA regex example. See http://regexr.com/3er68
# The original VersionRegex from DXA.NET is
(v\d*.\d*)
https://github.com/sdl/dxa-web-application-dotnet/blob/release/1.6/Sdl.Web.Common/Configuration/SiteConfiguration.cs
# The original SYSTEM_ASSETS_PATTERN is
\/system(\/v\d+\.\d+)?\/assets\/.*
https://github.com/sdl/dxa-web-application-java/blob/release/1.6/dxa-framework/dxa-common-impl/src/main/java/com/sdl/webapp/common/impl/localization/LocalizationImpl.java
# This is a very flex alternative regex
# just match all the /system/some-version/assets, also match /system/assets
(\/system\/(?:.*?\/)?assets)
# This regex needs URL to start with /system/v followed by a digit, also match /system/assets
(\/system\/(?:v.*\/)?assets)
# This regex wants the URL to start with /system/v followed by any version number with + - . digits and alphanumerical characters
(\/system\/(?:v[0-9A-Za-z\.\-\+]+\/)??assets)
# This regex only accepts URLs with v followed a semantic version number; This is too strict since /v1.6/ does not match with semantic versioning
(\/system\/v(([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?)?\/assets)
# These examples are matching correctly with the original DXA regex
/system/v1.6/assets/css/main.css
/system/v1.61/assets/css/main.css
/system/v123.678/assets/css/main.css
# This example is not mathcing with the original DXA .NET regex
/system/assets/css/main.css
# These examples are not mathcing with the original DXA JAVA regex
/system/v1/assets/css/main.css
/system/v1.6.1/assets/assets/css/main.css
# These URLs with scemantic versioning are not matching with the original DXA regexes
/system/v1.6.1/assets/css/main.css
/system/v1.6.1-a+s/assets/css/main.css
/system/v123.678.45-12/assets/css/main.css
/system/v123.678.45-ab/assets/css/main.css
/system/v123.678.45-ab-cd/assets/css/main.css
/system/v123.678.45-ab-cd+12/assets/css/main.css
/system/v123.678.45-ab-cd+12-34/assets/css/main.css
/system/v123.678.45-ab-cd+ab/assets/css/main.css
/system/v123.678.45-ab-cd+ab-cd/assets/css/main.css
# These examples are not matching with the original DXA regexes
/system/v1.6-1/assets/css/main.css
/system/v1.6.a/assets/css/main.css
/system/v1.6-a/assets/css/main.css
/system/v123.678.45/assets/css/main.css
/system/v123.678-45/assets/css/main.css
# These examples don't have to match
/system//assets/css/main.css
/system/1.6/assets/css/main.css
/system/bogusv1.6/assets/css/main.css
/system/v/assets/css/main.css
/system/v.6/assets/css/main.css
/system/v1./assets/css/main.css
/system/va/assets/css/main.css
/system/vabc/assets/css/main.css
/system/v1.6_1/assets/css/main.css
/system/v1.6_a/assets/css/main.css
/system/v123.678.-_abc12/assets/css/main.css
# These examples must not match
/bogussystem/v1.6/assets/css/main.css
/systembogus/v1.6/assets/css/main.css
/system/v1.6/bogusassets/css/main.css
/system/v12345/whatever
/system/vx/whatever
/system/v12-34/whatever
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment