RegExReplace Vice Versa

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Billykid
Posts: 96
Joined: 16 Sep 2019, 08:59

RegExReplace Vice Versa

Post by Billykid » 13 Apr 2021, 06:38

Hallo there,

I have two little questions in terms of RegExReplace.

Code: Select all

MyString := "This forum is {ABC} a very (001) nice place to [xyz999] learn AHK."
MsgBox % RegExReplace(MyString, "U)\(.*\)") 
; Result: This forum is {ABC} a very nice place to [xyz999] learn AHK.
; How can I get this result:
; (001) 

MyString := "This forum is {ABC} a very (001) nice place to [xyz999] learn AHK."
MsgBox % RegExReplace(MyString, "U)[\(\{\[].*[\)\}\]]")
; Result: "This forum is a very nice place to learn AHK."
; How can I get this result:
; {ABC} (001) [xyz999]
Thanks a lot for your help!
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: RegExReplace Vice Versa

Post by mikeyww » 13 Apr 2021, 06:50

Code: Select all

str := "This forum is {ABC} a very (001) nice place to [xyz999] learn AHK."
RegExMatch(str, "\(.+?\)", short), RegExMatch(str, "({.+}).*( \(.+\)).*( \[.+\])", long)
MsgBox, 64, Result, % short "`n`n" long := long1 long2 long3
Example:

Code: Select all

MyString := "This forum is {ABC} a very (001) nice place to [xyz999] learn AHK."
RegExMatch(MyString, "\(.*\)", test) 
MsgBox % test
Explained: RegExMatch
teadrinker
Posts: 4331
Joined: 29 Mar 2015, 09:41
Contact:

Re: RegExReplace Vice Versa

Post by teadrinker » 13 Apr 2021, 07:14

Code: Select all

MyString := "This forum is {ABC} a very (001) nice place to [xyz999] learn AHK."
MsgBox, % RegExReplace(MyString, "s).*?({.+?}|\(.+?\)|\[.+?])|.*", "$1 ")
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: RegExReplace Vice Versa

Post by mikeyww » 13 Apr 2021, 07:16

A great one!
Post Reply

Return to “Ask for Help (v1)”