AutoHotkey Community

It is currently May 27th, 2012, 1:43 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: RegEx Question
PostPosted: January 17th, 2010, 8:27 pm 
Offline

Joined: November 26th, 2008, 4:16 pm
Posts: 32
How to seperate and display "224Way Street" as "224 Way Street"?

What i've done only managed to find where 4W touch.

Code:
#SingleInstance
fileselectfile, csvfile
fileread,csv,%csvfile%
loop,parse,csv,`r,`n
   Loop,Parse,A_LoopField,CSV
if A_loopfield contains %address%
{
RegExMatch(A_Loopfield, "\d\D", address, 1)
NewAddress := RegExReplace(address, "\d\D", address, 0, -1, 1)
msgbox, %A_Loopfield% %newaddress%
}



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 17th, 2010, 8:36 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Code:
Addr = 224Way Street
NewAddr := RegExReplace(Addr, "(\d+)(\s*)(.+)", "$1 $3")
MsgBox, %NewAddr%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 17th, 2010, 8:57 pm 
Offline

Joined: November 26th, 2008, 4:16 pm
Posts: 32
tic,

Thanks works great. How would I most easily replace the incorrect data with this correct data in .csv?

Lname,Fname,info1,info2,address,etc,etc
smith,john,(null),(null),204Way Ln., etc,etc,


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 17th, 2010, 9:04 pm 
Offline

Joined: November 26th, 2008, 4:16 pm
Posts: 32
So now that "224WayRoad" has become "224 WayRoad" I need to know how to put a space before any Capitalized letter, if there is not already a space in front of said cap letter so that I'm left with ""224 Way Road"


Code:
#SingleInstance
fileselectfile, csvfile
fileread,csv,%csvfile%
loop,parse,csv,`r,`n
   Loop,Parse,A_LoopField,CSV
   {
Addr = %A_LoopField%
RegExMatch(A_Loopfield, "\d\D", nospace, 1)   
if A_loopfield contains %nospace%
{
Addr = %A_LoopField%
NewAddr := RegExReplace(Addr, "(\d+)(\s*)(.+)", "$1 $3")
;MsgBox, Old Address: %Addr%`rNew Address: %NewAddr%
FileAppend, %NewAddr%`r`n, addy.txt
}
else
FileAppend, %Addr%`r`n, addy.txt
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 17th, 2010, 10:06 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Code:
NewAddr := RegExReplace(NewAddr, "(\S)([A-Z])", "$1 $2")

(untested)

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 18th, 2010, 5:25 am 
Offline

Joined: November 26th, 2008, 4:16 pm
Posts: 32
Thanks! This works very well!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: bobbysoon, Google Feedfetcher, JSLover, Tipsy3000 and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group