1
votes

I need to figure out how to extract allo occurences of a pattern (eg: AAA | AAA) from a string like the one below:

InputString := "PGA|MGA v _ 914:00 x a: EDA|EFG v 7 913:42 x 5:: PFD|GRM"

RegexMatch(InputString, "([A-Z]{3})\|([A-Z]{3})", Match)

strMessage := "InputString = '" . InputString . "'"

strMessage .= "`nName = '" . Match1 . "'"

MsgBox, % strMessage

I tried this code but it 's clear that it isn't correct.

I also tried:

InputString := "PGA|MGA v _ 914:00 x a: EDA|EFG v 7 913:42 x 5:: PFD|GRM"

Pos:=RegExMatch( InputString, "g)([A-Z]{3})\|([A-Z]{3})", Match)

Msgbox % Match1

But nothing...maybe I'm doing something wrong in the syntax?

2
Please update your question's tags to show what language that's in. The format of a regex might (not likely, but still) depend on it. - mszymborski
I'm very sorry. I tried to put a tag like ahk or autohotkeys, but the system doesn't accept it. - bonzix
Oh it's fine then. It looks like they support Perl regex format if anyone else is curious. - mszymborski
And what a weird language they use, see the UnquotedOutputVar: autohotkey.com/docs/commands/RegExMatch.htm - mszymborski

2 Answers

0
votes

Link from the help documents Global matching and Grep (forum link) on RegExMatch page.

I found this page to be more helpful!

Try:

InputString := "PGA|MGA v _ 914:00 x a: EDA|EFG v 7 913:42 x 5:: PFD|GRM"

MsgBox % Format("Match #1 {1:}`nMatch #2 {2:}`nMatch #3 {3:}"
            , RegExMatchAll(InputString, "([A-Z]{3}[|][A-Z]{3})")*)

; Return Array of all Matches found!
RegExMatchAll(Input, Pattern, Pos=1) {
    matches := []
    While Pos := RegExMatch(Input, Pattern, m,Pos+StrLen(m))
       matches.push(m)
    return matches
}
0
votes

Try this -- g)([A-Z]{3}\|[A-Z]{3})

The g) bit should set the regex matching option to 'global' so all matches are captured instead of just the first one.

From AHK docs