2

I want my extension to support Joomla 4.2 and later, what should I write for the targetplatform in that case? Will 4.* do the trick?

Writing something like 4.[2|3] for the targetplatform is not a good option for me as it requires a manual effort every new minor Joomla version.

3

1 Answer 1

2

Well, I guess it kind of depends how far you want to pre-emptively include versions in your pattern:

  • 4.2 only: ^4\.2\b
  • 4.2 to 4.3: ^4\.[23]\b
  • 4.2 to 4.4: ^4\.[2-4]\b
  • 4.2 to 4.5: ^4\.[2-5]\b
  • 4.2 to 4.6: ^4\.[2-6]\b
  • 4.2 to 4.7: ^4\.[2-7]\b
  • 4.2 to 4.8: ^4\.[2-8]\b
  • 4.2 to 4.9: ^4\.[2-9]\b
  • 4.2 to 4.10: ^4\.([2-9]|10)\b
  • 4.2 to 4.11: ^4\.([2-9]|1[01])\b
  • 4.2 or higher in 4: ^4\.([2-9]|[1-9]\d+)\b ...yes, this ridiculously matches version 4.347 and beyond
  • 4.2 through 5: ^(5|4\.([2-9]|[1-9]\d+))\b

The important thing to note is that these patterns are matching only the front portion of the version string. If there are addition trailing characters, they are deemed unimportant. In other words, 4.6.3 will be matched by a pattern that allows 4.6; the trailing .3 is irrelevant to the logic.

The use of the word boundary (\b) could have been replaced with (?!\d) to ensure that the next character is not a digit -- but I prefer the brevity of \b. In all of my patterns, the character before the \b is a digit (considered a "word" according to \w), then the "word boundary" character insists that if there is a next character, it must be a "non-word" (something that matches \W).

Please see my earlier post for the explanation of some of the subpatterns.

p.s. As a note on @Dmitrijs's spitballed pattern of 4.[2|3], it is important to note that . represents a wildcard to the regex engine and will be satisfied by any non-newline character. Also, the square braced expression is called a "character class" -- it holds a list of all allowed characters. A character class does not respect the pipe character to mean "or" -- it will be literally interpreted as a pipe symbol. So as a worse case demonstration, 4.[2|3] will happily match 4&| ...which is not intended.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.