#1 : 16/04-16 19:27 Bernie2504
Posts: 17
|
Hi at all
i want to remove a space at end of a filenames by regular expression: e.g original: sinatra, frank - my way .mp3 corrected: sinatra, frank - my way.mp3 i have tried with the Replace method : text to be replaced: (.+)<space> replace with: \1 reg.exp.: tic this works fine, but i want to leave this method active for many different files if i do so, this method removed the last space in filename if there is no space at end of the file: e.g. original : sinatra, frank - my way.mp3 corrected : sinatra, frank - myway.mp3 that wrong - so, if there is no blank at the end of the filename, the filename should be leaved as it is (untouched). regards Bernd |
#2 : 16/04-16 23:17 Tester123
Posts: 92
|
Reply to #1:
You were nearly there. Try this instead: text to be replaced: (.+)<space>$ replace with: \1 reg.exp.: tic The $ is an anchor and means the end of the string. This means that the space must be at the end of the string. If you have more than one space at the end, then use this instead: text to be replaced: (.+?)<space>+$ The ? modifies the (.+) search to not be greedy, because normally the '.+' would match ALL the characters so that the subsequent <space> would not be found. It says "match as many characters as required, but leave enough to satisfy the rest of the regex that follows". Good luck on your journey learning regular expressions! |
#3 : 17/04-16 11:18 Bernie2504
Posts: 17
|
Reply to #2:
Hello Tester123, the only thing I can say: many thanks for the sound help your solution works really great ! and... yes I'm a learner ... hopefully I get there to where you already are :-) it's a long way .. best regards Bernd (Germany) |