spac3m0nk3y Posted July 17, 2007 Posted July 17, 2007 I'm trying to put together a script to copy certain files, but I'm having trouble with my RegExp. I currently have:\d+-\d+-\d+ (.*?)\.docwhich matches filenames like so:Johnson 07-17-2007 JDM.docSmith 07-12-2007 BKS.docI need a RegExp to recognize files like:Public 07-17-2007 PQRI JDM.docSmith 07-17 2007 ADD HRT.docJohnson 07-17-2007 2 TRK.docRight now, my regexp returns everything after the date and before .doc. I only need the part in red returned. If somebody could tell me if this is possible, or point me to a good regexp tutorial on how to do it, I would be grateful. Website: http://www.mayniac.org
GMK Posted July 17, 2007 Posted July 17, 2007 What are some examples of files that would be excluded?
spac3m0nk3y Posted July 17, 2007 Author Posted July 17, 2007 (edited) What are some examples of files that would be excluded?No files would be excluded. All the files in the directory would follow the same filename pattern, just some would have the extra characters before the initials. Edited July 17, 2007 by spac3m0nk3y Website: http://www.mayniac.org
spac3m0nk3y Posted July 17, 2007 Author Posted July 17, 2007 I don't suppose you could just copy all *.doc files?No, it's not that simple. I need the initials because I have to copy different files into different folders. Website: http://www.mayniac.org
Outshynd Posted July 17, 2007 Posted July 17, 2007 If it's always 3 initials, you could just use StringRight to return the 7 pertinent characters (including the .doc). Otherwise, you could StringSplit with a delimiter of " " and read the last value in the array, which would be "XXX.doc". As far as RegExp, I'm sure someone else will be much, much more help than I am.
spac3m0nk3y Posted July 17, 2007 Author Posted July 17, 2007 If it's always 3 initials, you could just use StringRight to return the 7 pertinent characters (including the .doc). Otherwise, you could StringSplit with a delimiter of " " and read the last value in the array, which would be "XXX.doc". As far as RegExp, I'm sure someone else will be much, much more help than I am.Yeah, I thought about doing it that way, but I was hoping there was a way I could do it with StringRegExp instead. I'm trying to learn a little more about RegExps, but this has me stumped. Website: http://www.mayniac.org
Toady Posted July 17, 2007 Posted July 17, 2007 why dont u just do. spare the headache... $string = StringSplit("Public 07-17-2007 PQRI JDM.doc", " ") MsgBox(0,"",StringRegExpReplace($string[$string[0]],"(.doc)","")) www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding
spac3m0nk3y Posted July 17, 2007 Author Posted July 17, 2007 why dont u just do. spare the headache... $string = StringSplit("Public 07-17-2007 PQRI JDM.doc", " ") MsgBox(0,"",StringRegExpReplace($string[$string[0]],"(.doc)","")) Ok, thanks, I'll give that a try. Website: http://www.mayniac.org
Toady Posted July 17, 2007 Posted July 17, 2007 (edited) Actually... $string = "Johnson 07-17-2007 2 TRK.doc" MsgBox(0,"",StringRegExpReplace($string,"(.*?) |(.doc)","")) Edited July 17, 2007 by Toady www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding
spac3m0nk3y Posted July 17, 2007 Author Posted July 17, 2007 Actually... $string = "Johnson 07-17-2007 2 TRK.doc" MsgBox(0,"",StringRegExpReplace($string,"(.*?) |(.doc)","")) That doesn't return anything. Your first StringRegExpReplace does return the initials though. Website: http://www.mayniac.org
Toady Posted July 17, 2007 Posted July 17, 2007 Any file extension.. $string = "Johnson 07-17-2007 2 TRK.doc" MsgBox(0,"",StringRegExpReplace($string,"(.*?) |(\..*)","")) www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding
Toady Posted July 17, 2007 Posted July 17, 2007 Dont return anything? It returns for me. www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding
Xenobiologist Posted July 17, 2007 Posted July 17, 2007 Hi, (?<=[ ])\w+(?=\.\w+) So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
spac3m0nk3y Posted July 17, 2007 Author Posted July 17, 2007 Hi, (?<=[ ])\w+(?=\.\w+) So long, Mega Ummm... thanks... I guess. I have no idea what that does. Website: http://www.mayniac.org
spac3m0nk3y Posted July 17, 2007 Author Posted July 17, 2007 Nevermind my last post, i got it. Website: http://www.mayniac.org
Toady Posted July 17, 2007 Posted July 17, 2007 Your welcome.... www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding
Xenobiologist Posted July 18, 2007 Posted July 18, 2007 Hi, it was meant to show your results like this: #include<Array.au3> ; Filename Global $str = 'Public 07-17-2007 PQRI JDM.doc Smith 07-17 2007 ADD HRT.doc Johnson 07-17-2007 2 TRK.doc' Global $re = StringRegExp($str, '(?<=[ ])\w+(?=\.\w+)', 3) _ArrayDisplay($re) So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now