regex groups.

Just starting out? Need help? Post your questions and find answers here.
jassing
Addict
Addict
Posts: 1745
Joined: Wed Feb 17, 2010 12:00 am

regex groups.

Post by jassing »

Maybe I misunderstand groups in PB...
I don't know if this is a pcre question or PB question.

here's regex101's take on it. (hint: look at 'match information')

Code: Select all

CreateRegularExpression(0,"^FWD:\[(?<pid>[0-9]{4})\] (?<prog>.+\.exe): (?<msg>.*)$")
x$ = "FWD:[1234] something else.exe: a bunch of text"

If MatchRegularExpression(0,x$)
  Debug RegularExpressionNamedGroup(0,"pid")
  Debug RegularExpressionNamedGroup(0,"prog")
  Debug RegularExpressionNamedGroup(0,"msg")
Else
  Debug "No match"
EndIf
but groups don't show up
Last edited by jassing on Fri Jun 09, 2023 2:12 am, edited 1 time in total.
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: regex groups.

Post by normeus »

One step missing:

Code: Select all

CreateRegularExpression(0,"^FWD:\[(?<pid>[0-9]{4})\] (?<prog>.+\.exe): (?<msg>.*)$")
x$ = "FWD:[1234] something else.exe: a bunch of text"
If ExamineRegularExpression(0,x$)
 While NextRegularExpressionMatch(0)
  Debug RegularExpressionNamedGroup(0,"pid")
  Debug RegularExpressionNamedGroup(0,"prog")
  Debug RegularExpressionNamedGroup(0,"msg")
Wend
EndIf
does that look right?

Thank you Jassing,
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
jassing
Addict
Addict
Posts: 1745
Joined: Wed Feb 17, 2010 12:00 am

Re: regex groups.

Post by jassing »

Norm! Thank you! Perfection. I did, indeed miss that - despite reading the help file a few times. Blinded for some reason.
Thank you!!!
Post Reply