| View previous topic :: View next topic |
| Author |
Message |
quicktest
Joined: 30 Jul 2004 Posts: 42
|
Posted: Mon Jun 30, 2008 6:06 pm Post subject: RegExReplace variable ref & semicolon in variable value |
|
|
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 |
|
 |
quicktest
Joined: 30 Jul 2004 Posts: 42
|
Posted: Mon Jun 30, 2008 6:32 pm Post subject: |
|
|
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 |
|
 |
pokercurious
Joined: 16 Dec 2007 Posts: 48
|
Posted: Mon Jun 30, 2008 9:19 pm Post subject: |
|
|
| 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 |
|
 |
quicktest
Joined: 30 Jul 2004 Posts: 42
|
Posted: Mon Jun 30, 2008 9:56 pm Post subject: |
|
|
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 |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1390 Location: The Interwebs
|
Posted: Mon Jun 30, 2008 11:09 pm Post subject: |
|
|
| 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 |
|
 |
quicktest
Joined: 30 Jul 2004 Posts: 42
|
Posted: Wed Jul 02, 2008 1:38 pm Post subject: |
|
|
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 |
|
 |
|