Sign in to follow this  
Followers 0
Cusem

Stringregexp help

4 posts in this topic

#1 ·  Posted (edited)

Hey guys,

sorry to bother you with another (well, it is my first) StringRegExp question, but I've been reading the helpfile and read some forum posts, but it's all abacadabra to me and I guess for the people that are familiar with regular expressions, this shoud be a piece of cake.

I want extract a date from a filename like "Sleep Behaviour - Robert Haskins - appendix 22 - 18-03-2006.doc"

So I want to extract the "18-03-2006" from the Filename string.

I want to do this because I want to put them in front of the filename (like "2006-03-18 - Sleep Behaviour - Robert Haskins - appendix 22"), so the files automatically get sorted by date when I open the folder.

I'll code this myself (I guess I'll manage), but I just don't know how regular expressions work, so I don't know how to extract the date.

I tried StringRegExp(STRING ABOVE, "..-..-...", 2) but this doesn't seem to work.

Edited by Cusem

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <array.au3>
Local $aSRE = StringRegExp($sStr, "(?s)(?i)(\d{2}-\d{2}-\d{4})\.doc", 3)
_ArrayDisplay($aSRE)oÝ÷ ØGbµ*+¯ ­ 
 khGb·b¶j×¢±©pk+¦§uçZܨ¹ªÞ§Ú!j÷¯j¸¨ºÇ±µéì춬r¥w
+«0zYZºÚ"µÍÚ[ÛYH Ø^K]LÉÝÂØØ[   ÌÍØTÔHHÝ[ÔYÑ^
    ÌÍÜÔÝ  ][ÝÊÜÊJÚJJ ÌLÙÌKIÌLÙÌKIÌLÙÍJIÌLËÌLÝÊÉ][ÝËÊBÐ^QÜ^J  ÌÍØTÔJ

\d = Digit

\w = Word character

{N} = Find that exact number of the search before it)

(Just in case you were wondering where the magic was coming from.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Works like a charm!

Thanks!

Share this post


Link to post
Share on other sites

Works like a charm!

Thanks!

As you are going to have to reformat the date to yyyy-mm-dd format to get them to sort correctly you might be interested in the small modification I've made to SmOke_N code

#include <array.au3>
Dim $sStr = "Sleep Behaviour - Robert Haskins - appendix 22 - 18-03-2006.doc"
Local $aSRE = StringRegExp($sStr, "(?s)(?i)((\d{2})-(\d{2})-(\d{4}))\.\w+", 3)
_ArrayDisplay($aSRE)

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

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