 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Titan
Joined: 11 Aug 2004 Posts: 4975 Location: /b/
|
Posted: Sun Feb 04, 2007 5:59 pm Post subject: RegEx Powered Dynamic Hotstrings |
|
|
Dynamically add regular expression type hotstrings.
Example:
| Code: | hotstrings("now#", "%A_Now%")
hotstrings("(B|b)tw", "%$1%y the way")
hotstrings("(\d+)\/(\d+)%", "percent") ; try 4/50%
Return
percent:
p := Round($1 / $2 * 100)
Send, %p%`%
Return |
Download from SVN _________________

Last edited by Titan on Thu Sep 03, 2009 6:28 pm; edited 3 times in total |
|
| Back to top |
|
 |
hughman
Joined: 11 Feb 2007 Posts: 92
|
Posted: Wed Feb 21, 2007 12:10 pm Post subject: Re: RegEx Powered Dynamic Hotstrings |
|
|
| Titan wrote: | | Dynamically add regular expression type hotstrings. |
Thinks.I'll have a try. |
|
| Back to top |
|
 |
rjwilmsi
Joined: 18 May 2005 Posts: 17
|
Posted: Wed Feb 28, 2007 6:59 pm Post subject: |
|
|
Hmm, this seems interesting, but I can't get it to work.
I've pasted the function and examples into my autohotkey.ini file and reloaded it. I then expected that if I typed Btw in notepad it would be converted to By the way, and if I typed btw it would be converted to by the way. Am I totally missing the point? Does this script not effectively add regex support to hotstrings? |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 4975 Location: /b/
|
Posted: Sun Mar 04, 2007 3:05 pm Post subject: |
|
|
| rjwilmsi wrote: | | Does this script not effectively add regex support to hotstrings? | It does, that was probably a bad example. Try hs("gr[ea]y", "{#}CCC") - it replaces 'grey' or 'gray' with its hex colour code. _________________
 |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1317 Location: USA
|
|
| Back to top |
|
 |
talkasab
Joined: 28 May 2007 Posts: 2
|
Posted: Tue Jul 17, 2007 1:09 pm Post subject: |
|
|
I like the idea of the dynamic hotstrings and I like the idea of regular expressions in them. But, as other people have described, I'd like to find a way to make dynamic hotstrings that behave more like regular, default hotstrings in that they wait for an non-word character before firing the replacement text.
For example, when defined using the hs() function above, the "btw" entry will expand to "by the way" without waiting for a space or comma afterward. (Which makes it impossible to define multiple hotstrings that use the same root.)
For example, I'd "lb" to expand to "pound", but "lbrt" to expand to liberate, and I haven't figured out yet how to do that using the hs() function above.
(The reason I don't want to use the #Hostring directive or syntax is that I'd like these hotstrings to be dynamically created as part of a compiled script.)
Thanks,
T |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 4975 Location: /b/
|
Posted: Tue Jul 17, 2007 1:24 pm Post subject: |
|
|
That is an important feature that's currently lacking. I've been meaning to update this script for a long time. I'll try work on it soon and release version 2. _________________
 |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 7698 Location: Germany (but I only speak English)
|
Posted: Tue Jul 17, 2007 2:33 pm Post subject: |
|
|
please try
| Code: |
hs("(B|b)tw\W", "%$1%y the way")
|
_________________
Unless noted, all code is UNTESTED.
Answers Here: 1.(Loops, Viruses, etc.) 2.Search 3.RTFM 4.Ask for Help.
PMs will be ignored unless you are hiring me. |
|
| Back to top |
|
 |
talkasab
Joined: 28 May 2007 Posts: 2
|
Posted: Tue Jul 17, 2007 4:07 pm Post subject: |
|
|
| engunneer wrote: | please try
| Code: |
hs("(B|b)tw\W", "%$1%y the way")
|
|
Does that work for you? Because that doesn't get expanded at all for me. (FWIW, I also thought about using regular expressions to try to test for end-of-word characters, but couldn't get it to work.)
T |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 4975 Location: /b/
|
Posted: Tue Jul 17, 2007 4:11 pm Post subject: |
|
|
That would work if you typed something like 'btw.' or 'btw!', but these aren't nice solutions so I'll continue working on an update. _________________
 |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 7698 Location: Germany (but I only speak English)
|
Posted: Tue Jul 17, 2007 4:36 pm Post subject: |
|
|
I didn't have a chance to try it. I also didn't have time to look up the regex, maybe \s was the right one? _________________
Unless noted, all code is UNTESTED.
Answers Here: 1.(Loops, Viruses, etc.) 2.Search 3.RTFM 4.Ask for Help.
PMs will be ignored unless you are hiring me. |
|
| Back to top |
|
 |
rjwilmsi
Joined: 18 May 2005 Posts: 17
|
Posted: Mon Dec 17, 2007 7:15 pm Post subject: handling of spaces |
|
|
Hi all,
I've been using this for a while now but have got stuck by one issue:
say i define an entry like this (I have this problem with other examples):
hs("ann(a|e)" , "Ann%$1%")
now this correctly changes:
anna -> Anna
anne -> Anne
however, spaces don't seem to be counted, so these are also incorrectly changed;
ann a -> aAnna
ann e -> aAnne
So it would seem that spaces are ignored by the regex matching? Am I right and can anybody tell me how to fix it?
Thanks |
|
| Back to top |
|
 |
rjwilmsi
Joined: 18 May 2005 Posts: 17
|
Posted: Fri Dec 21, 2007 8:11 am Post subject: |
|
|
| Please, anybody? I haven't yet resolved this. |
|
| Back to top |
|
 |
tonne
Joined: 06 Jun 2006 Posts: 1475 Location: Denmark
|
Posted: Fri Dec 21, 2007 8:49 am Post subject: |
|
|
Try this:
| Code: | hs(c, a = "") {
static d, b, q
global $
v = `n,€,~$,Numpad,BS,Space
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
d := 1
}
If a
Return, !!b .= c . v2 . a . v1
If c = %v3%%v5%
Return, !!q := SubStr(q, 1, -1)
If c = %v3%%v6%
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 =
}
~$space::
_hs:
hs(A_ThisHotkey)
Return |
_________________ there's a dog barking close within the range of my ear
sounds like he wants to escape the chain
he would probably bite me to death if he could
but the chain lets me spit in his face
- Kashmir |
|
| Back to top |
|
 |
rjwilmsi
Joined: 18 May 2005 Posts: 17
|
Posted: Fri Dec 21, 2007 6:23 pm Post subject: |
|
|
Thanks, that's perfect!
For others who may be interested, it's possible to exclude returns and tabs in a similar fashion:
| Code: | hs(c, a = "") {
static d, b, q
global $
v = `n,€,~$,Numpad,BS,Space,Tab,Return
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
d := 1
}
If a
Return, !!b .= c . v2 . a . v1
If c = %v3%%v5%
Return, !!q := SubStr(q, 1, -1)
If c = %v3%%v6%
Return, !!q := SubStr(q, 1, -1)
If c = %v3%%v7%
Return, !!q := SubStr(q, 1, -1)
If c = %v3%%v8%
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 =
}
~$space::
~$return::
~$tab::
_hs:
hs(A_ThisHotkey)
Return |
|
|
| 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
|