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
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
...
Easy (?) RegEx help requested
Easy (?) RegEx help requested
Last edited by Guest10 on 03 Nov 2013, 15:24, edited 1 time in total.
Re: RegEx help requested - 100313
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!
?
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
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
...
Re: Easy (?) RegEx help requested
none of the following worked. i am missing something:
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
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.
Re: Easy (?) RegEx help requested
I would do it this way
StringReplace, %A_Space%%A_Space%, ¢
StringSplit, Str, ¢
MsgBox, % Str1
StringReplace, %A_Space%%A_Space%, ¢
StringSplit, Str, ¢
MsgBox, % Str1
Re: Easy (?) RegEx help requested
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
Re: Easy (?) RegEx help requested
thanks, both versions work great (i had no idea of StringSplit )! my special thanks to TLM for the super-compact and regal RegEx solution.
- smorgasbord
- Posts: 493
- Joined: 30 Sep 2013, 09:34
Re: Easy (?) RegEx help requested
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 ?
Re: Easy (?) RegEx help requested
wow, thanks, smorgasbord! the power of RegEx unleashed.
- smorgasbord
- Posts: 493
- Joined: 30 Sep 2013, 09:34
Re: Easy (?) RegEx help requested
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, " [^.]*")
Re: Easy (?) RegEx help requested
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, " [^.]*")
Re: Easy (?) RegEx help requested
My RegEx wouldn't do it, but TLM's might work.
Re: Easy (?) RegEx help requested
thanks, that particular one works when the space that comes before the "date string" is not variable (according to my tests).
just me wrote:My RegEx wouldn't do it, but TLM's might work.