[RegExReplace] Replace First or X Occurrences Only!

Get help with using AutoHotkey and its commands and hotkeys
User
Posts: 282
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”

Who is online

Users browsing this forum: Mipha and 51 guests