Sign in to follow this  
Followers 0
spac3m0nk3y

Regular Expression and filenames help

18 posts in this topic

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+ (.*?)\.doc

which matches filenames like so:

Johnson 07-17-2007 JDM.doc

Smith 07-12-2007 BKS.doc

I need a RegExp to recognize files like:

Public 07-17-2007 PQRI JDM.doc

Smith 07-17 2007 ADD HRT.doc

Johnson 07-17-2007 2 TRK.doc

Right 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.

Share this post


Link to post
Share on other sites



What are some examples of files that would be excluded?

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by spac3m0nk3y

Share this post


Link to post
Share on other sites

I don't suppose you could just copy all *.doc files?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Hi,

(?<=[ ])\w+(?=\.\w+)

So long,

Mega

Ummm... thanks... I guess. I have no idea what that does.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0