Jump to content

Regular Expression and filenames help


Recommended Posts

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.

Link to comment
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.

Link to comment
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.

Link to comment
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

Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...