AutoHotkey Community

It is currently May 24th, 2012, 10:08 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Regex hotstrings - how?
PostPosted: April 11th, 2007, 9:35 pm 
Offline

Joined: May 18th, 2005, 11:03 am
Posts: 30
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 11th, 2007, 10:21 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8646
Location: Salem, MA
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


_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 11th, 2007, 10:25 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8646
Location: Salem, MA
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.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 11th, 2007, 10:50 pm 
Offline

Joined: May 18th, 2005, 11:03 am
Posts: 30
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: ... wser/Typos I reckon I can convert that easily enough.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Cephei1, Xx7 and 68 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group