 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
rjwilmsi
Joined: 18 May 2005 Posts: 30
|
Posted: Wed Apr 11, 2007 8:35 pm Post subject: Regex hotstrings - how? |
|
|
Okay, I want to have regex support in hotstrings. For (trivial) example I want something like
:*:[aio]vly"::$1vely
so if I type livly it is corrected to lively, lovly to lovely etc. but 'tuvly' is not changed. I know I could do this by having two seperate hotstrings, but I have ideas in mind which could combine 20 hotstrings into one regex hotstring if this works.
I've looked at http://www.autohotkey.com/forum/viewtopic.php?t=16367 which might be what I want, but if it is I don't get it. If anybody is kind enough to answer with lines of code as examples, I will paste them in to the end of my autohotkey.ini file, reload the script and expect it to work. If I have to do something else please tell me! |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 8255 Location: Maywood, IL
|
Posted: Wed Apr 11, 2007 9:21 pm Post subject: |
|
|
Titan's Script is a really the best way to go. It's very cool and powerful.
put this at the top of your script:
| Code: |
hs("[aio]vly","%$1%vely")
|
Put this at the end:
| Code: |
hs(c, a = "") { ; Titan v1
static d, b, q
global $
v = `n,€,~$,Numpad,BS
StringSplit, v, v, `,
If !d {
Loop, 104
Hotkey, % Chr(42 * !!RegExMatch(t := Chr(32 + (x := A_Index))
, "[a-z]")) . v3 . (x > 94 ? v4 . x - 95 : t), _hs
Hotkey, %v3%%v5%, _hs
}
If a
Return, !!b .= c . v2 . a . v1
If c = %v3%%v5%
Return, !!q := SubStr(q, 1, -1)
If GetKeyState("Shift", "P") or GetKeyState("Capslock", "T")
StringUpper, c, c
Else StringLower, c, c
q .= SubStr(c, StrLen(v3) + !!InStr(c, v4) * StrLen(v4) + 1 + !!InStr(c, "*"))
Loop, Parse, b, %v1%
{
If (c := RegExMatch(q, SubStr(t := A_LoopField, 1
, InStr(t, v2) - 1) . "$", $)) and t {
f += RegExMatch(t, ".+" . v2 . "(.+)", l)
SendInput, % "{BS " . StrLen($) . "}"
Transform, l, Deref, %l1%
If IsLabel(l)
GoSub, %l%
Else SendInput, %l%
}
}
If f
q =
}
_hs:
hs(A_ThisHotkey)
Return
|
_________________
(Common Answers) |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 8255 Location: Maywood, IL
|
Posted: Wed Apr 11, 2007 9:25 pm Post subject: |
|
|
btw, it doesn't exactly do what you want, since livly becomes lvely, but the regex may be fixable for this (but I don't know enough Regex to do it myself)
If you are just looking for word corrections, search the forum for wikipedia, and you should find a script that uses wikipedia to manage your word replacements, so you don't have to type each one and make good regexes. _________________
(Common Answers) |
|
| Back to top |
|
 |
rjwilmsi
Joined: 18 May 2005 Posts: 30
|
Posted: Wed Apr 11, 2007 9:50 pm Post subject: |
|
|
Thanks for that. I've got the script working now ... it seems it didn't work before as it's not possible to simply add the hs function and examples to my existing autohotkey.ini but I can run a separate script containing the function and example alongside my .ini file. That must have been the only combination I didn't try.
And you're right, that regex needs to be more like hs("([aio])vly","%$1%vely")
to work. I've already seen that wikipedia list, but want to use the more powerful list at http://en.wikipedia.org/wiki/Wikipedia:AutoWikiBrowser/Typos I reckon I can convert that easily enough. |
|
| 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
|