Improve handling of regex groups in CustomDimension extraction #16141
Labels
c: Custom Dimensions
For issues related to the Custom Dimensions plugin.
Enhancement
For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Milestone
Bug:
There may be more than one "(" or ")" in regular expression used for dimension extraction although there is only one capturing group. Examples include non-capturing groups, modificators like "(?i)", and escaped character sequences like "(". Regular expressions with more than one "(" or ")" are rejected currently.
Example:
(?i)example.com/(?:SOME_PART/)?([a-z]{2})(?:$|/)
This is captures exactly one group, yet is not allowed. (This is what I wanted to use in my project, actually.)
Root cause:
Counting the number of "(" or ")" as is done in https://github.com/piwik/plugin-CustomDimensions/blob/master/Dimension/Extraction.php#L46 is just wrong: It does not ensure that there is exactly one capturing group.
Better solutions:
Short term: Remove this useless test. Add an example or warning regarding the number of groups.
Long term: Include "live-preview" of matches as described in another bug report. Warn when more than one group captures.
The text was updated successfully, but these errors were encountered: