[RegExReplace] Replace First or X Occurrences Only!

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User
Posts: 407
Joined: 26 Jun 2017, 08:12

[RegExReplace] Replace First or X Occurrences Only!

14 Oct 2018, 00:36

I found the code below and I think it is really interesting!

Anyway, just sharing it! (If there are better ways to do the same, please share here!)

Code: Select all

String := ""
. "- a - a - a"  "`r`n"
. "- a - a - a"  "`r`n"
. "- a - a - a"  "`r`n"


msgbox, % RegExReplace(String, "s)^((.*?a){0}.*?)a", "$1b")

	;s), forces "." to match new lines! (`r`n)

	;{0} for first a
	;{1} for second a
	;{2} for third a
	; and so on ...!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: gongnl, Rohwedder and 251 guests