AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

regexreplace() woes..

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
regexreplace?
Guest





PostPosted: Mon Oct 08, 2007 7:49 pm    Post subject: regexreplace() woes.. Reply with quote

Anyone skilled or know how to work with regexreplace()?? I have a string "Login:User|||Password" and I need to get the User and Password. for example..

Login:Bob|||123
User = Bob
Password = 123

So how would I go about extracting them from a string like this? Theres a tripple pipe line in the middle of the two ("|||")...

Anyone? Thanks in advance.
Back to top
philz



Joined: 05 Jun 2007
Posts: 87
Location: USA

PostPosted: Mon Oct 08, 2007 8:50 pm    Post subject: Reply with quote

Code:
regexmatch(inputstring,"^.+?(?=:)",login)
;takes the inputstring "Login:User|||Password" and returns
;the login in the variable "login"
;the ^ means start at the beginning of the string
;the .+? means find one or more of any character until
;the next criteria occurs
;the next criteria is (?=:) which is a lookahead assertion

regexmatch(inputstring,"(?<=:).+?(?=|||),User)
;stors the username from the inputstring and puts it
;into the variable called "user"

regexmatch(inputstring,"(?<|||).*?$",Password)
;stores the password from inputstring into the variable, "Password"

This is untested, but it should work.
if there is a problem it would be with my assertions. you could edit the regexmatches and use stringreplace from there to get your desired result
Back to top
View user's profile Send private message Send e-mail
regexreplace?
Guest





PostPosted: Mon Oct 08, 2007 9:14 pm    Post subject: Reply with quote

it works, thanks. And thx for the helpful comments!
Back to top
Guest






PostPosted: Mon Oct 08, 2007 9:20 pm    Post subject: Reply with quote

looks like I spoke too soon... I thought maybe all that was missing was the second quote mark in your second line of code.. but i guess that wasn't the issue. Its returning the 1st letter of the user in the string, thats it..
Back to top
philz



Joined: 05 Jun 2007
Posts: 87
Location: USA

PostPosted: Tue Oct 09, 2007 10:04 am    Post subject: Reply with quote

oh DUH

the | is an either or symbol and needs to be escaped with a \
here is your new code string.
Code:
regexmatch(inputstring,"(?<=:).+?(?=\|{3})",User)
;the {3} is saying that it must repeat the | three times

I suggest you download titans Regex Analyzer.

That should be useful to you in learning regular expressions.
They are a VERY useful tool.
Back to top
View user's profile Send private message Send e-mail
Guest






PostPosted: Thu Oct 11, 2007 11:01 pm    Post subject: Reply with quote

thanks it works now
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group