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 variable ref & semicolon in variable value

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



Joined: 30 Jul 2004
Posts: 42

PostPosted: Mon Jun 30, 2008 6:06 pm    Post subject: RegExReplace variable ref & semicolon in variable value Reply with quote

Hi all,

I have 2 basic syntax questions but could not find the answers via a quick search, thus am hoping some bright minds could enlighten this aging one. I apologize in advance if these have been discussed before.


1. Using variable names in RegExReplace
In this example:

Code:
NewStr := RegExReplace("user-name-address", "address", %ADDRESS%) 


Is there anyway to add text in addition to %ADDRESS%, for example:

Code:
NewStr := RegExReplace("user-name-address", "address", "User Resides In: "%ADDRESS%", USA") 


Each time I attempt a mix of variables and texts to replace, AutoHotKey throws an error and halts the execution.


2. Assigning semicolon into a variable
Is there anyway to assign the following text into a variable?

Quote:
; User; Name; Address;


When I simply add a variable name = in front of this string, the first semicolon turns the rest into a comment.
Back to top
View user's profile Send private message
quicktest



Joined: 30 Jul 2004
Posts: 42

PostPosted: Mon Jun 30, 2008 6:32 pm    Post subject: Reply with quote

Found the solution for issue #2 with the escape character `. Had tried \ and ; but forgot to try `. Thanks forum.

If anyone could help with issue #1, it would be greatly appreciated.
Back to top
View user's profile Send private message
pokercurious



Joined: 16 Dec 2007
Posts: 47

PostPosted: Mon Jun 30, 2008 9:19 pm    Post subject: Reply with quote

Code:
NewStr := RegExReplace("user-name-address", "address", "User Resides In:" . address_var . ", USA")

Untested, but that should work.


Last edited by pokercurious on Mon Jun 30, 2008 11:16 pm; edited 1 time in total
Back to top
View user's profile Send private message
quicktest



Joined: 30 Jul 2004
Posts: 42

PostPosted: Mon Jun 30, 2008 9:56 pm    Post subject: Reply with quote

pokercurious,

That worked great, thanks much! I'm wondering if that's a common convention for Regular Expressions? Because I went through the AutoHotKey help file and could not find this in the RegExMatch/RegExReplace/Quick Reference sections. I would suggest this information be added into the help file in case I didn't mis-read.
Back to top
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 1145
Location: The Interwebs

PostPosted: Mon Jun 30, 2008 11:09 pm    Post subject: Reply with quote

No, that is common expression convention. Only literal strings should be contained within double quotes, any variable references should be outside of the quotes.
Back to top
View user's profile Send private message AIM Address
quicktest



Joined: 30 Jul 2004
Posts: 42

PostPosted: Wed Jul 02, 2008 1:38 pm    Post subject: Reply with quote

Krogdor,

If you look at the sample code I provided, my variable name was outside of the quotes, which I agree is common knowledge. What I have not seen before, however, was the way the variable references had to be notated, namely surrounded with " . " (space, dot, space), which I could not find mentioned in the help file. This is what I wish could be included in the documentation to help other noob scripters like me.
Back to top
View user's profile Send private message
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