"_" to " " findrep
"(.)[.](.)#" to "\1\2" regexp
"^( +)(.)( +)(..)" to "\2\4" regexp
"^( +)(.)" to "\2" regexp
"(.)(\ )(..)#" to "\1\3" regexp
In order these are for turning _ to space, removing brackets and text inside them, removing extra spaces in the end of the filename and removing extra spaces in front of the filename. I'm sure there are smarter ways to do some of these but these have worked fine.
Earlier I have had these set as two buttons (left and right click on single button) because having all that stuff in one button doesn't work properly. Now I'd like to use scripting mode to do them.
Basically what I want to do is a) remove underscores, b) remove brackets and all stuff inside them, c) remove extra spaces.
Have you had a look at the Rename Scripting forum, specifically the Titlecase and multiple Regular Expressions examples?
They should be a good starting point for a script like this. (The multiple Regular Expressions example is intended to be used as the basis for exactly this kind of thing.)
The only obstacle is to convert the regexp syntax into the one which VBScript uses but that usually just means turning \1, \2, etc. into $1, $2. Be sure to test your script in a safe place first, just in case, though.
Yeah I got it working now. One thing that still kind of bothers me is this:
File name is something like "[252542AFBB] blaablaablaa [CDBR456272].avi"
re.Pattern = "[.*]" doesn't work properly, matches everything and returns empty line when set to replace with ""
re.Pattern = "[.](.)[.*]", replace with "$1" on the other hand does work but I was kind of hoping to have a regexp that removes brackets no matter where they are in the filename.
[quote="kasakka"]
re.Pattern = "[.*]" doesn't work properly, matches everything and returns empty line when set to replace with ""[/quote]
I think you just need to put the part of the expression that you want to extract in brackets. \1 (or $1 in VBScript) will turn into the first thing in brackets, but in the pattern you have there isn't anything in brackets so the \1 (or $1) turns into nothing.
i.e. instead of
[.*]
try
[(.*)]
Let us know if that doesn't work. Maybe I've misunderstood what you want the expression to do.
[quote="kasakka"]Yeah I got it working now. One thing that still kind of bothers me is this:
File name is something like "[252542AFBB] blaablaablaa [CDBR456272].avi"
re.Pattern = "[.*]" doesn't work properly, matches everything and returns empty line when set to replace with ""
re.Pattern = "[.](.)[.*]", replace with "$1" on the other hand does work but I was kind of hoping to have a regexp that removes brackets no matter where they are in the filename.
Any idea what I'm doing wrong here?[/quote]
You are getting trapped by greedy vs non-greedy regular expressions.
Not tested (I've still only got DOpus 6 on another machine ) but in most versions of regular expression putting a "?" after should make it find the nearest bracket so both bracket ranges in the above should get replaced by null.
I think Alec's right. I didn't notice the other pair of brackets! (It's been a long day.)
If the ? in "[.*?]" doesn't solve it (I don't know if it will work or not, regexp syntax varies so much from program to program, so give it a try) then an alternative might be something like this:
[[^[]*] <-- EDIT: This is rubbish! See Enigma's correction below.
That, if I haven't messed up the regexp due to lack of sleep, should match a [, then as many characters as possible -- so long as those characters don't include a second [ -- until a ].
(Random sleepy thought: Unicode should have special regexp characters so we don't have to escape normal characters all the time. Except when dealing with meta-regexps, which would probably drive a person insane anyway so aren't worth worrying about! Maybe Unicode already has such characters. There's some pretty weird stuff in there already.)
I know how you feel - I'm getting by far too little sleep myself at the moment. Yesterday I spent more than an hour investigating a CSS error in a web page I'm creating, and the solution was more than obvious - I just had forgotten about a setting I had written into a second CSS file...
That's the moment to stop working and take a nap, no matter how urgently you have to finish a project...
[quote="Alec_Burgess"][quote="kasakka"] .... One thing that still kind of bothers me is this:
File name is something like "[252542AFBB] blaablaablaa [CDBR456272].avi"
....
[/quote]
You are getting trapped by greedy vs non-greedy regular expressions.
...
ie. try
re.Pattern = "[.*?]" replaced by ""[/quote]
If the above works you probably want to change it to:
re.Pattern = "\s?[.*?]\s?" replaced by ""[/quote]
This would ALSO get rid of leading or trailing space before/after the bracketed string. (This use of "?" in \s? is different than the .? - it matches zero or one of the "thing" before it. The ? after .? converts a normally greedy match to non-greedy.
gets changed to: New ===.txt
It makes four matches in the above:
[Te[x]t]
[Do[um[asdf]
[fdsa]
[e]n]t]
but considers the "====" to not be bracketed at all.
Note: for testing I changed your expression to:
[code] [\[\(][^\]\)]*[^\[\(]*(\]|\))[/code]
same thing but it considers both square and round brackets to be identical
PCRE regular expressions have a concept called recursive matching.
I suspect this is the engine that DOpus 9 is using?
This expression matches arbitrarily deeply nested round parethesis:
[code] \(((?>[^()]+)|(?R))*\)[/code]
or adjusting it as above to handle [ & ( and ] and )
[code][\(\[]((?>[^()\[\]]+)|(?R))*[\)\]][/code]
so my counter-example "New [Tet] [Do[um[asdf]===[fdsa][e]n]t].txt" ==> "New .txt"
Note if the brackets are deliberately unbalanced by tacking an extra "]" on the end we get:
"New [Te[x]t] [Do[um[asdf]===[fdsa][e]n]t]].txt" ==> "New ].txt"
Yes, I know. Actually this is all I had come up with out of my head before my head blew up.
[quote]This expression matches arbitrarily deeply nested round parethesis:
Code:
(((?>[^()]+)|(?R))*) [/quote]
I gues that won't work in a VBScript/JScript, as I may remember the RegExp class used by the scripting engine allows only Positive/Negative Lookaheads (?=...)/(?!...) beside Backreferences (\1,\2,...), but I may not be right.