Are there more than one space before an underline charachter? … did you try the code snippet? … it removes ONLY the space befor the underline. The other spaces remain in the string.
Should work as Olaf says.
But if you have more than one space or need to match an exact number of spaces before the underscore you can add a quantifier.
E.g. ‘\s{1}(?=_)’
But that seem to be pretty strange filename requirements if you ask me
A tip is to use a regex tester, there are several online that simplifies regex testing.
E.g. https://regex101.com/
Olaf - no chance of double space there as I have another cmdlet which suppresses the double whitespace at a position.
Fredrik - yes its the archived data for the last decade and am assisting to set things right …phase by phase
and i have used “https://rubular.com/” for coming to a conclusion of finding those files - using regex, now got stuck with the rename options within powershell
In these cases the position is fixed that is 10th position of the string and so removing space then renaming the file is pretty straightforward.
So the assistance required here is for the space before the second instance of underscore “_”
This is the logic I came up with for the resolving the cases of have the space just before the “Underscore” , if any better logic can be implemented, am open for them…
I really do not understand what’s wrong with my suggestions. The code snippet I posted matches ONLY spaces occuring in front of an underline - NO OTHER OCCURENCES OF ANY WHITE SPACE CHARACHTERS.