Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Clipboard Search & Replace v1.50


  • Please log in to reply
16 replies to this topic
tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
Clipboard Search & Replace v1.50
Search and replace text that is in your clipboard.

this is a Plugin to my personal script Mango. But I feel it was worthy of its own topic :).
a simple script that mimics the basic windows Find and Replace dialogue, except this has a few more features.
There is a Preview button which allows you to see the changes before they are applied to the Clipboard.
Regex lets you find/replace using regular expression patterns.

Posted Image

Download:
<!-- m -->https://ahknet.autoh...ngo/Replace.ahk<!-- m -->

note: since this is a plugin for another one of my scripts, there is not hotkey to run/open the window. So you may want to add one.

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
Perhaps add a history and/or favourites so you don't have to
keep typing frequently used search/replace combinations 8)

I have have my own buddy so I don't need it <!-- m -->http://www.autohotke...pic.php?t=42971<!-- m --> but could be a useful addition :wink:

  • Guests
  • Last active:
  • Joined: --
A 'Whole word' feature would be nice too when replace all is checked

For example in the following sentence 'her other coat was red'
When i find the word 'her' and replace it with his.

It results to: his othis coat was red.
When what i really wanted was - his other coat was red

Would this be possible to acheive??

tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
yes, I know I need "whole word only". But I honestly have no idea how to achieve this.

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


  • Guests
  • Last active:
  • Joined: --
Logically we need to check for spaces to the left and right of the word to be replaced

Example:

sentence=her other coat is red

var1=her
var2=his

check character to the left of %var1% to be replaced and store the value into var_left
check character to the right of %var1% to be replaced and store the value into var_right


if both %var_left% and %var_right% contain spaces then replace %var1% with %var2%

else move on to next word in %sentence%



Unfortunatly i am no expert and can not offer a solution and also we need to think about speed if processing large text files. If anybody can offer a solution then this script would really come in handy for me.

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
Add checkbox for Whole word, instead of stringreplace use RegExReplace, example:
Sentence=her other coat is red
Sentence:=RegExReplace(sentence, "\bher\b", "his")
MsgBox % Sentence

\b means "word boundary", which is like an anchor because it doesn't consume any characters. It requires the current character's status as a word character (\w) to be the opposite of the previous character's. It is typically used to avoid accidentally matching a word that appears inside some other word. For example, \bcat\b doesn't match catfish, but it matches cat regardless of what punctuation and whitespace surrounds it. Capital \B is the opposite: it requires that the current character not be at a word boundary.

Also the spaces trick won't work if the word is followed by a comma, dot or is at the start or end of a string (there is no space in those cases before/after)

tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
1 issue:
if I replace StringReplace with a REGEX, then you cannot toggle the regex mode on/off. And having a constant Regex=on can be verry annoying.
I was playing around and had some issues besides that, soo, I'll keep thinking :)

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


  • Guests
  • Last active:
  • Joined: --

soo, I'll keep thinking


Shame adding a checkbox is causing problems but at least in the meantime it will still work with 'whole word' replacment by inputting the \b \b directly into the 'Find what?' field around what you want it to find
when RegEx mode is selected.

\bher\b


Regular Expression are my nightmare :(

tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
Update.
Added Whole Word Only mode.

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


  • Guests
  • Last active:
  • Joined: --
Yey ....Thank you tidbit, .. :D

This handy script and your time spent adding the whole word replace feature are very much appreciated indeed.

tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
Thanks for the kind words Guest :).

New version, 1.40.
Added a regex quick reference.
Made the GUI resizable.

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
Version 1.50 is out.
[*:32gnu3w2]Auto update of the preview display.
[*:32gnu3w2]Fixed some limitations when not in regex mode.
[*:32gnu3w2]Fixed the regex help sheet to be more accurate.
[*:32gnu3w2]Fixed drawing issues.
[*:32gnu3w2]Code optimization.
[*:32gnu3w2]Added support for tabs in both Find and Replace boxes.
[*:32gnu3w2]Added support for NewLines in the replace box.

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


awannaknow
  • Members
  • 372 posts
  • Last active: Feb 02 2017 01:01 AM
  • Joined: 14 Jun 2009
Thank you tidbit this is helpful script !
I may learn a bit reading your script.
Good work.

tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
Thanks awannaknow.
what are you going to try and learn from it? regex? or just the concept? or other?

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


awannaknow
  • Members
  • 372 posts
  • Last active: Feb 02 2017 01:01 AM
  • Joined: 14 Jun 2009
Well, as a beginner I have everything to learn . . .
regex I don't know about and may learn when and if needed; I want to concentrate on ahk.
As your script has both I may learn a bit of them if I'm able to grasp some of your code, which is not sure at all . . .
The search and replace also is actually what I try to do with a simple hotstring script.
Also I just started trying to make GUI follow my will . . .
:roll: