Skip to content

Simplify regex in MappingUtils.evaluateFileNameMapping - #68

Open
elharo wants to merge 1 commit into
masterfrom
fix/remove-unnecessary-regex-group
Open

Simplify regex in MappingUtils.evaluateFileNameMapping#68
elharo wants to merge 1 commit into
masterfrom
fix/remove-unnecessary-regex-group

Conversation

@elharo

@elharo elharo commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Remove the unnecessary empty capture group and __artifact prefix trick from the RegexBasedInterpolator pattern in MappingUtils.evaluateFileNameMapping.

Problem

The previous regex used startRegex='\\@\\{(' and endRegex=')?([^}]+)\\}@' with thisPrefixPattern='__artifact', creating the pattern:

\@\{(__artifact)?([^}]+)\}@

This contained an unused optional group (__artifact)? that served no real purpose -- the __artifact string was a dummy prefix intended to be filtered out by the optional group, but since the custom prefix/suffix already delimit @{...}@ expressions, the prefix filtering is redundant.

Fix

The new approach uses an empty startRegex with the full capture pattern in endRegex and passes null for thisPrefixPattern:

RegexBasedInterpolator interpolator = new RegexBasedInterpolator("", "\\@\\{([^}]+)\\}@");
return interpolator.interpolate(expression, (String) null);

This produces the simpler pattern \@\{([^}]+)\}@ with the key captured directly in group 1.

Verification

All existing tests pass without modification:

  • completeMapping
  • noVersionMapping
  • mappingWithGroupId
  • mappingWithClassifier
  • mappingWithNullClassifier
  • mappingWithOptionalClassifier (MWAR-212)

Closes #67

Remove the unnecessary empty capture group and __artifact prefix
trick from the RegexBasedInterpolator pattern.

The previous regex used startRegex='\@\{(' and
endRegex=')?([^}]+)\}@' with thisPrefixPattern='__artifact',
creating a complex pattern with an unused optional group
wrapping the dummy __artifact string.

The new approach uses an empty startRegex with the full
pattern '\@\{([^}]+)\}@' in endRegex and passes null
for thisPrefixPattern, achieving the same result more
directly.

Closes #67
@elharo
elharo marked this pull request as draft August 19, 2026 19:10
@elharo
elharo marked this pull request as ready for review August 19, 2026 19:11
@elharo
elharo requested a review from slachiewicz August 19, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unused empty capture group in regex pattern

1 participant