Easy (?) RegEx help requested

Get help with using AutoHotkey and its commands and hotkeys
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Easy (?) RegEx help requested

03 Nov 2013, 13:24

i have a list of song titles. the pattern is as follows:
M:\Here's an Idea? May 12, 2008.mp3
all items in the list have a date string at the end before .mp3. this date is always separated from the first part of the string by 2 spaces. how can i write a script so that this double space and the following date string are removed and the final string looks like this:?
M:\Here's an Idea?.mp3 :ugeek:

List:
M:\Here's an Idea? May 12, 2008.mp3 ; Remove 2 spaces between Idea? and May and May 12, 2008
M:\Sleight of Hand April 5, 2006.mp3 ; Remove 2 spaces between Hand and April and April 5, 2006
...
Last edited by Guest10 on 03 Nov 2013, 15:24, edited 1 time in total.
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: RegEx help requested - 100313

03 Nov 2013, 14:35

actually, list is not required! just a single line:
how to convert
M:\Here's an Idea? May 12, 2008.mp3 ; Remove 2 spaces between Idea? and May and May 12, 2008
to
M:\Here's an Idea?
OR all chars up to .mp3 including the 2 spaces in the line (there is always a double space somewhere in the line but always before .mp3). everything before the double space stays!
?
Guest10 wrote:i have a list of song titles. the pattern is as follows:
M:\Here's an Idea? May 12, 2008.mp3
all items in the list have a date string at the end before .mp3. this date is always separated from the first part of the string by 2 spaces. how can i write a script so that this double space and the following date string are removed and the final string looks like this:?
M:\Here's an Idea?.mp3 :ugeek:

List:
M:\Here's an Idea? May 12, 2008.mp3 ; Remove 2 spaces between Idea? and May and May 12, 2008
M:\Sleight of Hand April 5, 2006.mp3 ; Remove 2 spaces between Hand and April and April 5, 2006
...
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Easy (?) RegEx help requested

03 Nov 2013, 16:31

none of the following worked. i am missing something: :( :ugeek:

Str := "M:\Here's an Idea? May 12, 2008.mp3" ; 2 spaces between Idea? and May
RegExMatch(Str,"M+(.*?)(?=(\s\s))", Found)
msgbox % Found
RegExMatch(Str,"M+(.*?)(?=(\s){2,})", Found)
msgbox % Found
Last edited by Guest10 on 03 Nov 2013, 20:50, edited 1 time in total.
Morpheus
Posts: 119
Joined: 04 Oct 2013, 05:09

Re: Easy (?) RegEx help requested

03 Nov 2013, 19:09

I would do it this way

StringReplace, %A_Space%%A_Space%, ¢
StringSplit, Str, ¢
MsgBox, % Str1
User avatar
TLM
Posts: 1582
Joined: 01 Oct 2013, 07:52
GitHub: TLMcode
Contact:

Re: Easy (?) RegEx help requested

03 Nov 2013, 19:41

Code: Select all

str =
(
M:\Here's an Idea? May 12, 2008.mp3 ; Remove 2 spaces between Idea? and May and May 12, 2008
M:\Sleight of Hand April 5, 2006.mp3 ; Remove 2 spaces between Hand and April and April 5, 2006
)

nStr := RegExReplace(str,"(\w:.*?)\h\w+[\d\h]+,.*?\d{1,4}(\.mp3)","$1$2")

msgbox % nStr
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Easy (?) RegEx help requested

03 Nov 2013, 20:48

thanks, both versions work great (i had no idea of StringSplit :shock:)! my special thanks to TLM for the super-compact and regal RegEx solution. :D
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Easy (?) RegEx help requested

03 Nov 2013, 21:27

oh just saw that after posting in the other forums.
:)

Code: Select all

string =
(
M:\Here's an Idea?  May 12, 2008.mp3
)
MsgBox % RegExReplace(string, "(.*)\s{2}(.*)(\.mp3)", "$1$3")
John ... you working ?
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Easy (?) RegEx help requested

03 Nov 2013, 22:10

wow, thanks, smorgasbord! the power of RegEx unleashed. :)
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Easy (?) RegEx help requested

04 Nov 2013, 02:05

lol
:)
John ... you working ?
just me
Posts: 6979
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Easy (?) RegEx help requested

04 Nov 2013, 11:56

For this special case:

Code: Select all

Songs := ["M:\Here's an Idea?  May 12, 2008.mp3", "M:\Sleight of Hand  April 5, 2006.mp3"]
; Remove two spaces and all following characters which are not a dot (.)
For Each, Song In Songs
   MsgBox, 0, Song %A_Index%, % RegExReplace(Song, "  [^.]*")
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Easy (?) RegEx help requested

04 Nov 2013, 13:57

thanks, just me. what if in a more general case, the space just in front of the date string is not always "2 spaces" but could vary (1 space, 3 spaces, 4 spaces, etc.). is it possible to still remove all these spaces AND the date string?
just me wrote:For this special case:

Code: Select all

Songs := ["M:\Here's an Idea?  May 12, 2008.mp3", "M:\Sleight of Hand  April 5, 2006.mp3"]
; Remove two spaces and all following characters which are not a dot (.)
For Each, Song In Songs
   MsgBox, 0, Song %A_Index%, % RegExReplace(Song, "  [^.]*")
just me
Posts: 6979
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Easy (?) RegEx help requested

05 Nov 2013, 04:11

My RegEx wouldn't do it, but TLM's might work.
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Easy (?) RegEx help requested

05 Nov 2013, 08:21

thanks, that particular one works when the space that comes before the "date string" is not variable (according to my tests). :geek:
just me wrote:My RegEx wouldn't do it, but TLM's might work.

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Bral, chenj209, eblanc, F4Jonatas, Gigadroid, Google [Bot], KiddoV, SilasDeVis, wyatterp, Xtra and 124 guests