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 

RegEx Powered Dynamic Hotstrings
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Sun Feb 04, 2007 6:59 pm    Post subject: RegEx Powered Dynamic Hotstrings Reply with quote

Dynamically add regular expression type hotstrings.

Example:
Code:
hs("now#", "%A_Now%")
hs("(B|b)tw", "%$1%y the way")
hs("(\d+)\/(\d+)%", "percent") ; try 4/50%

percent:
p := Round($1 / $2 * 100)
Send, %p%`%
Return


Download/view with documentation
_________________

RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")


Last edited by Titan on Fri Dec 21, 2007 10:45 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
hughman



Joined: 11 Feb 2007
Posts: 23

PostPosted: Wed Feb 21, 2007 1:10 pm    Post subject: Re: RegEx Powered Dynamic Hotstrings Reply with quote

Titan wrote:
Dynamically add regular expression type hotstrings.


Thinks.I'll have a try.
Back to top
View user's profile Send private message
rjwilmsi



Joined: 18 May 2005
Posts: 13

PostPosted: Wed Feb 28, 2007 7:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Sun Mar 04, 2007 4:05 pm    Post subject: Reply with quote

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.
_________________

RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
ahklerner



Joined: 26 Jun 2006
Posts: 1090
Location: USA

PostPosted: Fri Apr 06, 2007 12:52 am    Post subject: Reply with quote

Used it here
http://www.autohotkey.com/forum/viewtopic.php?t=18110
Back to top
View user's profile Send private message
talkasab



Joined: 28 May 2007
Posts: 2

PostPosted: Tue Jul 17, 2007 2:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Tue Jul 17, 2007 2:24 pm    Post subject: Reply with quote

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.
_________________

RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
engunneer



Joined: 30 Aug 2005
Posts: 6307
Location: Pacific Northwest, US

PostPosted: Tue Jul 17, 2007 3:33 pm    Post subject: Reply with quote

please try
Code:

hs("(B|b)tw\W", "%$1%y the way")

_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
talkasab



Joined: 28 May 2007
Posts: 2

PostPosted: Tue Jul 17, 2007 5:07 pm    Post subject: Reply with quote

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
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Tue Jul 17, 2007 5:11 pm    Post subject: Reply with quote

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.
_________________

RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
engunneer



Joined: 30 Aug 2005
Posts: 6307
Location: Pacific Northwest, US

PostPosted: Tue Jul 17, 2007 5:36 pm    Post subject: Reply with quote

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 otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
rjwilmsi



Joined: 18 May 2005
Posts: 13

PostPosted: Mon Dec 17, 2007 8:15 pm    Post subject: handling of spaces Reply with quote

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
View user's profile Send private message
rjwilmsi



Joined: 18 May 2005
Posts: 13

PostPosted: Fri Dec 21, 2007 9:11 am    Post subject: Reply with quote

Please, anybody? I haven't yet resolved this.
Back to top
View user's profile Send private message
tonne



Joined: 06 Jun 2006
Posts: 1143
Location: Denmark

PostPosted: Fri Dec 21, 2007 9:49 am    Post subject: Reply with quote

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
View user's profile Send private message
rjwilmsi



Joined: 18 May 2005
Posts: 13

PostPosted: Fri Dec 21, 2007 7:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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