 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Fri Jan 09, 2009 2:05 pm Post subject: RegEx Callbacks |
|
|
From recently, there are some efforts to introduce callouts to RegEx engine.
Before it gets done, this module can be used to achieve something similar.
Download Documentation
Example:
Replace the server names with base name and ping information:
| Code: | text=
(Ltrim
www.google.com
www.yahoo.com
www.autohotkey.com
)
msgbox % RegEx_Replace(text, "www\.(.+?)\.com", "MyFunc")
return
MyFunc($, $1) {
RunWait, cmd /C ping %$% -n 1 >out, ,Hide
FileRead out, out
RegExMatch(out, "Reply from .+? time=([0-9]+)ms", o)
return $1 " (" o1 " ms)"
} |
_________________
 |
|
| Back to top |
|
 |
kiropes
Joined: 21 Mar 2007 Posts: 71
|
Posted: Sat Jan 10, 2009 2:21 pm Post subject: |
|
|
| the links don't work |
|
| Back to top |
|
 |
freakkk
Joined: 29 Jul 2005 Posts: 179
|
Posted: Sat Jan 10, 2009 2:23 pm Post subject: |
|
|
| kiropes wrote: | | the links don't work | Yes they do _________________ .o0[ corey ]0o. |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Sat Jan 10, 2009 4:21 pm Post subject: |
|
|
Interesting! Such short AHK code, with great functionality!
- Is it basically the same as replacing all matches with special strings, and then use a Parse loop to process those strings?
- Can this function be used for finding all matches, even within other matches? Like listing all substrings of a 4 letter haystack: abcd --> a, b, c, d, ab, bc, cd, abc, bcd, abcd. |
|
| Back to top |
|
 |
haichen
Joined: 05 Feb 2007 Posts: 189 Location: Osnabrück, Germany
|
Posted: Sat Jan 10, 2009 7:19 pm Post subject: |
|
|
| kiropes wrote: | | the links don't work |
You probably forget to translate to your local language.
Here's the german version:
| Code: | MyFunc($, $1) {
RunWait, cmd /C ping %$% -n 1 >out, ,Hide
FileRead out, out
RegExMatch(out, "Antwort von .+? Zeit=([0-9]+)ms", o)
return $1 " (" o1 " ms)"
} |
|
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Sun Jan 11, 2009 1:26 am Post subject: |
|
|
| Laszlo wrote: | | Is it basically the same as replacing all matches with special strings, and then use a Parse loop to process those strings? |
I think this allows for broather usage, not to mention far easier.
| Laszlo wrote: | | - Can this function be used for finding all matches, even within other matches? Like listing all substrings of a 4 letter haystack: abcd --> a, b, c, d, ab, bc, cd, abc, bcd, abcd. |
No. The next matching starts after previous one (see the code, you can change that line for other effects if you want). I don't think you can do that with integrated RegExp functions, right ?
The only note you should be aware so far is that you can't access named sub-patterns in callback function. You can name function arguments the way you want so there is no need to use them, generally. _________________
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|