RegEx help Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Loop
Posts: 160
Joined: 07 Jan 2019, 14:51

RegEx help

Post by Loop » 20 May 2022, 14:26

Hi,
x and y stand for any characters
Final result , should look like this:

Hello,
Auto
Hot
Key

Thx



Code: Select all

Str=
(join`r`n
Hello,

xxxx

©yyyy

Auto
Hot
Key
)

MsgBox, % RegExReplace(Str, "\R\s+\R\s+©.*+\R")

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: RegEx help

Post by teadrinker » 20 May 2022, 15:22

Loop wrote: Final result , should look like this
If that's the only thing you need, just do like this:

Code: Select all

Str=
(join`r`n
Hello,

xxxx

©yyyy

Auto
Hot
Key
)
MsgBox, Hello,`nAuto`nHot`nKey
Seriously, you described the end result, but did not describe the rule by which the RegEx should act.

User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: RegEx help  Topic is solved

Post by rommmcek » 20 May 2022, 15:23

Code: Select all

RegExReplace(Str, "\R\R.*\R\R©.*\R")
Last edited by rommmcek on 20 May 2022, 15:32, edited 1 time in total.

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: RegEx help

Post by Chunjee » 20 May 2022, 15:23

Hows this?

Code: Select all

MsgBox, % RegExReplace(Str, "\R{0,1}\w+\R+©\w+\R+")
; =>
/*
Hello,

Auto

Hot

Key
*/

Cubex
Posts: 8
Joined: 06 Sep 2014, 06:23

Re: RegEx help

Post by Cubex » 21 May 2022, 04:12

Code: Select all

/*
Join syntax not correct -> missing space
join no need
*/
Str=
(join `r`n
Hello,

xxxx

©yyyy

Auto
Hot
Key
)
MsgBox, % Str
p := 0
while p := RegExMatch(Str, "(\p{Lu}\p{Ll}+,?)", match,p+1)
  all .= match1 "`n"
MsgBox, % all

User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: RegEx help

Post by rommmcek » 21 May 2022, 08:12

@Cubex: Great RegEx skills and sharp eye regarding syntax!
P.s.:
Loop wrote:
20 May 2022, 14:26
x and y stand for any characters
What if "any" starting char happens to be upper case? Then it wouldn't work correctly, however your contribution is precious!

Post Reply

Return to “Ask for Help (v1)”