asad41163
asad41163

Reputation: 49

AHK: Find text and Replace all

How do I replace the letters ve at the end of each word with the letters on. Please see the picture:I know that this word is not correct but it is an example only to clarify Such a code sentence:

#IfWinActive ahk_class Chrome_WidgetWin_1
F2::
    Clipboard := ""
    Send, ^+{End}
    Send, ^c
    ClipWait
    Clipboard := RegExReplace(Clipboard, "^(.*?)i(.*)", "$1o$2")
    Send, ^v
return

Upvotes: 1

Views: 1854

Answers (2)

Yane
Yane

Reputation: 837

Replace the

Clipboard := RegExReplace(Clipboard, "^(.*?)i(.*)", "$1o$2")

with

Clipboard := RegExReplace(Clipboard, "ve\b", "on")

The \b makes it match only the "ve" at the end of words, for example, it will change "vetvetve" to "vetveton" Note that RegExReplace is case sensitive (it will not change "VETVETVE"), to make it case-insensitive use the i) option:

Clipboard := RegExReplace(Clipboard, "i)ve\b", "on")

Upvotes: 1

Salvador Hernandez
Salvador Hernandez

Reputation: 309

You don't need a regex for this one. You can instead use a simple string replace

#IfWinActive ahk_class Chrome_WidgetWin_1
F2::
    Clipboard := ""
    Send, ^+{End}
    Send, ^c
    ClipWait
    Clipboard := StrReplace(Clipboard, "ve", "on")
    Send, ^v
return

Upvotes: 0

Related Questions