Regex not matching?

Advanced Renamer forum
#1 : 26/12-20 04:08
thiago
thiago
Posts: 2
Hi,

I'm trying to change dots to spaces, except for dates (10.10.10), so I was trying the following regex:

(\D.)\.(.\D) -> replace for -> \1 \2

I read that as:
Group1: any non-digit, followed by any char
. (the dot I want to remove
Group2: any char, followed by a non-digit

I know it might not be the best solution, but still, it doesn't seem to be working properly.

partial Filename: and.andi.part1.aaa.sd.mp4-aaa.mp4
result: and.andi part 1.aaa sd.mp4-aaa.mp4

I just cant understand why some of those dots are not being replaced. 'nd.an', ' 1.aa', 'sd.mp' should all match my regex.

I'm on windows 10 64 bit, AR 3.87


26/12-20 04:08
#2 : 26/12-20 17:39
David Lee
David Lee
Posts: 600
There are several issues in your solution - and unless I'm missing something this will be quite tricky if you want to cover all possibilities.

The best I can suggest is to do this in 3 steps...
1: replace the dots in the date with a temporary character
2: remove all remaining dots
3: reverse step 1

Use a "List replace" method with three lines...

1) Replace: "(\d{2})\.(\d{2})\.(\d{2})" with "\1:\2:\3"
2) Replace: "." with space
3) Replace ":" with "."

I've used ":" as a temporary character because it is illegal in a Windows filename and so shouldn't appear in the original name.


26/12-20 17:39
#3 : 26/12-20 19:11
thiago
thiago
Posts: 2
Reply to #2:
Thank you for your solution. I didn't think about using a temp character. that is way easier.

But still, is the regex match on this software unreliable? I tried some regex testers online to confirm, and that regex should have worked in the example I gave


26/12-20 19:11
#4 : 26/12-20 23:23
David Lee
David Lee
Posts: 600
Reply to #3:
First there is a typo in your example: "and.andi.part1.aaa.sd.mp4-aaa.mp4". From the rest of your query I assume that there should be a space in "part 1".

Applying your regex "(\D.)\.(.\D)" and replacement "\1 \2", selecting "Occurence = All" gives me the result: "and andi part 1 aaa.sd mp4-aaa(10.10.10)", which is what you should expect.

The "." in "aa.sd" will NOT be selected since the previous match "t1.aa" will result in the remaining string being "a.sd.mp4-aaa" so the next (and final) match will be "sd.mp".

Your other problem is that the regex "(\D.)\.(.\D)" will not reject only date strings.

I WAS missing something and a better solution is...
Replace : "(\d{2}\.\d{2}\.\d{2})\.|\."
with: "\1 "

This uses the regex OR operator ("|") to select EITHER a date string (dd.dd.dd) followed by a dot OR (if that is not found) the next dot on its own. If a date string is matched then it will be saved in \1 otherwise \1 will contain null.

Because the "." is the final character in the pattern the regex will resume with the next character after each match until the end of the filename is reached, so ALL dots will be replaced by spaces except those in a pattern of the form "dd.dd.dd".





26/12-20 23:23 - edited 27/12-20 11:24