AutoHotkey Community

It is currently May 27th, 2012, 6:10 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Help with a string
PostPosted: October 12th, 2010, 12:34 am 
Offline

Joined: September 20th, 2010, 7:53 pm
Posts: 16
Location: USA
Hey everyone I have a new question
I am trying to figure out how to strip out numbers from a peice of text such as
Quote:
i live on 1234 oaktree
Any help?
Would it be possible to store the stripped digits in a new variable?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2010, 12:52 am 
Offline

Joined: August 25th, 2009, 4:52 pm
Posts: 321
Code:
String = i live on 1234 oaktree
String2 := RegexReplace( String, "\D" )
String3 := RegexReplace( String, "\d" ) 
Msgbox %String%`n%String2%`n%String3%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2010, 12:53 am 
Offline

Joined: February 29th, 2008, 8:36 pm
Posts: 901
Location: Vault 7
Definitely regex:
Code:
txt := "i live on 1234 oaktree"
RegExMatch(txt,"\d+",match)
MsgBox '%match%'


Edit: I see I've been scooped. My version will get the a single group of numbers from the string. sbc's version will gather all the numbers anywhere.

_________________
ImageDebugging,Container,FileContainer,Object Preferences,ShellFileOperation


Last edited by Rapte_Of_Suzaku on October 12th, 2010, 1:02 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2010, 12:58 am 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
I have not used Regex much (I'm starting on you dime :wink:) but does this work for you?
Code:
Adress=I live on 1234 oaktree
Pos:=RegExMatch(Adress, "\d+" , Out)
RegExMatch(Adress, "\D+" , Out2)
RegExMatch(Adress, "\D+" , Out3, Pos)
MsgBox %Out%, %Out2%%Out3%


Edit: I was slow too. Looks like RegExReplace works better in this instance, thanks sbc.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 2nd, 2010, 4:30 am 
Offline

Joined: September 20th, 2010, 7:53 pm
Posts: 16
Location: USA
Thanks for the examples :!: This reg ex stuff is neat :!: I want to try to match each group of numbers, can reg ex match each group of numbers :?: Like if I have
Quote:
I live on 1234 oaktree, 5 miles north of 1253 elm street
can reg ex give me
Quote:
1234
5
1253


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 2nd, 2010, 5:00 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
This is an example of how to use RegEx in a while loop to traverse a string and retrieve all matches:

Code:
var=I live on 1234 oaktree, 5 miles north of 1253 elm street
Pos=1
While   Pos :=   RegExMatch(var,"\d+",m,Pos+StrLen(m))
   res .=   ((A_Index=1) ? "" : "`n")   m
MsgBox %   res
return

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


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: HotkeyStick, Wicked and 58 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