Jump to content

Help create script to Copy to Clipboard Paste RegEx Results


Recommended Posts

So been messing with this idea in my freetime and everytime I feel like I made the right connection, just one small thing does not work.

The idea would be this:

Select text in a document or webpage and use a hotkey to copy it to the clipboard and run a given RegEx filter on it, push it back to the clipboard in its modified state so that when I paste into a document I get the results of the RegEx.

 

I found this code that I think is a good base for adding text to the clipboard:

#include <GuiConstantsEx.au3>

; AutoIt Code: http://www.autoitscript.com/
$gui = GUICreate('', 500, 300, 0, 0)

; input that will receive richtext clipboard data
$input_clipboard = GuiCtrlCreateInput('my hidden input', 0, 0, 0, 0)

; copy plaintext to clipboard: ctrl+shift+c (normal copy to clipboard ctrl+c)
HotKeySet('^+c', 'ClipPutPlainText') ; ctrl+shift+c

; replaces richtext in clipboard with plaintext
Func ClipPutPlainText()
    ; set input value to whatever is currently in clipboard
    GUICtrlSetData($input_clipboard, ClipGet())
    ; put plaintext data in clipboard
    ClipPut(GUICtrlRead($input_clipboard))
EndFunc

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd 

and I had this working for RegEx

#include <array.au3>

$array = StringRegExp("(My String)", "(My RegEx)", 3)

For $i = 0 To UBound($array) - 1
    MsgBox(0, "", $array[$i] & @CR)
Next

I tried to push $input_clipboard into my RegEx and then take those results back to the clipboard but I just get return codes.

I tried _ArrayToClip() without too much luck.

Should be rather easy and it was a good project for me to practice on but I think it's time to ask for a bit of help.

Regards,

Edited by ViciousXUSMC
Link to comment
Share on other sites

I don't really know if I understood the question but something like this should work ;)

HotKeySet('^+c', 'ClipPutPlainText') ; ctrl+shift+c
HotKeySet('^+s', '_Exit') ; ctrl+shift+s

While 1
    Sleep(100)
WEnd

Func ClipPutPlainText()
    $sClipGet = ClipGet()
    $sClipGet = StringRegExpReplace($sClipGet, "a", "(o_o )"); Just an example replacing letter a to (o_o )
    ClipPut($sClipGet)
EndFunc   ;==>ClipPutPlainText

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Cheers,

sahsanu

Edited by sahsanu
Link to comment
Share on other sites

StringRegExpReplace if much better suited to what I understand from the OP since it always returns a string, whether or not the match (replacement) succeeds or fails. That sems to fit to the term "filter" pretty well.

Now StringRegExp is more problematic: a failure returns an array or not. Next, in the general case, what processing should be done to the array elements: concatenate them blindly or somehow grouped by number of captures at every match, or what?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...