Replace Text

Share actions you've created here.
Post Reply
Posts: 12
Joined: Wed Jul 06, 2011 2:16 pm

Replace Text

Post by Austin » Wed Jul 20, 2011 4:22 pm

For some time I have wanted a 'Template' feature in 3DC that would prompt me to replace a specific string within a clipboard item. So, I build a simple Action to prompt me for a regex string and a replacement string so that i can get the same functionality.

Language: Vbscript

Code: Select all

'Author: Austin James
'Date:   7/13/2011

'This action prompts the user to input a RegEx expression to search for in the value of the clipboard
'item.  Then, it prompts the user to input a replacement string.  Finally, the action replaces the
'RegEx expression with the replacement string.

'Initialize variables
Dim strReplace
Dim objRegExp
'Create RegEx object and set the global attribute to True so that it will replace every occurance found
Set objregexp = New regexp = True
'Obtain the search pattern (default is text surrounded by hashes (#))
objRegExp.pattern = Inputbox("Enter Regular Expression Pattern to look for.","Pattern","#.+?#")
'Obtain the replacement string
strReplace = Inputbox("Enter text that will replace pattern","Replace")
'Replace each occurance of the search patter with the replacement string and place back on clipboard
Clipboard.Value = objRegExp.replace(Clipboard.Value, strReplace)
Set objregexp = Nothing

Post Reply