Regex need help (tough one) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
keylo
Posts: 52
Joined: 21 Oct 2020, 21:03

Regex need help (tough one)

02 Feb 2022, 12:53

Hi Guys,
Is there a way I can do basic operation using regexreplace?
in the following csv lines I want to add "4" to the second field

Code: Select all

csv=
(
1, 45 , 765756
1, 56 , 654654
1, 900 , 545809
)
the output should be

Code: Select all

1, 49 , 765756
1, 60, 654654
1, 904, 545809
I'm trying to avoid loops in my script, is there a way this could be done using regexreplace with only 1 line of code ?
braunbaer
Posts: 483
Joined: 22 Feb 2016, 10:49

Re: Regex need help (tough one)  Topic is solved

02 Feb 2022, 13:19

Code: Select all

Global Outputstring
csv=
(
1, 45 , 765756
1, 56 , 654654
1, 900 , 545809
)
Outputstring:=""
RegExReplace(csv, "(\d+\D+)(\d+)(\D*\d*\D*)(?CCallNewStr)")
msgbox %Outputstring%
return

CallNewStr(Match)
{
    Outputstring .= Match1 (Match2+4) Match3
}
[Mod edit: [code][/code] tags added.]
keylo
Posts: 52
Joined: 21 Oct 2020, 21:03

Re: Regex need help (tough one)

02 Feb 2022, 14:01

Thanks @braunbaer but it doesn't work, the output is blank
braunbaer
Posts: 483
Joined: 22 Feb 2016, 10:49

Re: Regex need help (tough one)

02 Feb 2022, 14:10

Are you sure you did not make a mistake while copying? Did you include the function CallNewStr(Match) at the end of the script?
I tested the script, it produces exactly the output you want.

Image
Last edited by braunbaer on 02 Feb 2022, 14:14, edited 1 time in total.
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: Regex need help (tough one)

02 Feb 2022, 14:13

Must have copied only the visible part of the script in the code box without scrolling/expanding/selecting all. It would be blank without the function and not produce an error.
keylo
Posts: 52
Joined: 21 Oct 2020, 21:03

Re: Regex need help (tough one)

02 Feb 2022, 14:21

@braunbaer ,Thanks so much , it works fine :clap: . sorry, I didn't copy the function.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], mstrauss2021, peter_ahk, Spawnova, william_ahk, zephyrus2706 and 358 guests