EliziumNet / Loopz

PowerShell iteration utilities with additional tools like the Parameter Set Tools
https://eliziumnet.github.io/Loopz/
MIT License
3 stars 0 forks source link

Rename-Many; Anchored regex for Start/End agrressively filters out items that should not be #140

Closed plastikfan closed 3 years ago

plastikfan commented 3 years ago

The Anchored functionality introduced for Start/End anchors was designed to try and avoid processing items that already matched the intended operation;; ie if we want to move a particluar token to the Start, if it already appears to be there then skip this item.

However, there is a slight flaw in this logic. If the Pattern specified is too general, then the Anchored regex will match when we don't mean it to. eg:

given a file: '02-06 Airwaves.mp3'

we wish to move the 2nd of the 2 digit numbers (06) to the start.

Because, there is already a 2 digit number at the start, then the Anchored regex matches and then skips this item.

Even if adjusted the Anchored pattern was modified to be the actual captured token, in this case '06', if the item did actually start with '06', then the Anchored regex would still match and therefore skip.

The Anchored regex works best when the Pattern is complex. So perhaps this is best solved using an override parameter, than disables the Anchored facility.

Actually, the best way to fix this is to check where the pattern match occurs. If the pattern match index says 0 and Start is specified, then we can skip. Similar for end except that detecting the end is not as easy is checking the index being equal to 0.