CreateRegularExpression: non-capturing group?

Just starting out? Need help? Post your questions and find answers here.
hss
User
User
Posts: 69
Joined: Thu Mar 08, 2007 6:02 pm

CreateRegularExpression: non-capturing group?

Post by hss »

hello,

unfortunately, PB seems to ignore ?: (non-capturing group);
matches include <file>/</file> .. any workaround?

Code: Select all

If CreateRegularExpression(0, "(?:<file>)(.*?)(?:</file>)",#PB_RegularExpression_DotAll  )
    Dim Result$(0)
    NbFound = ExtractRegularExpression(0, "<xml><test>nn</test><file>File.txt</file><data>...</data><file>Yes.exe</file></xml>", Result$())
    For k = 0 To NbFound-1
      Debug Result$(k)
    Next
  Else
    Debug RegularExpressionError()
  EndIf
User avatar
JHPJHP
Addict
Addict
Posts: 2251
Joined: Sat Oct 09, 2010 3:47 am

Re: CreateRegularExpression: non-capturing group?

Post by JHPJHP »

Does the following "Positive Lookbehind" fit your requirements?

Code: Select all

If CreateRegularExpression(0, "(?<=file>)[^<]*", #PB_RegularExpression_DotAll)
  Dim Result$(0)
  NbFound = ExtractRegularExpression(0, "<xml><test>nn</test><file>File.txt</file><data>...</data><file>Yes.exe</file></xml>", Result$())
  For k = 0 To NbFound-1
    If Result$(k) : Debug Result$(k) : EndIf
  Next
Else
  Debug RegularExpressionError()
EndIf
You can also expand your search criteria:

Code: Select all

If CreateRegularExpression(0, "(?<=file>|<data>)[^<]*", #PB_RegularExpression_DotAll)
  Dim Result$(0)
  NbFound = ExtractRegularExpression(0, "<xml><test>nn</test><file>File.txt</file><data>...</data><file>Yes.exe</file></xml>", Result$())
  For k = 0 To NbFound-1
    If Result$(k) : Debug Result$(k) : EndIf
  Next
Else
  Debug RegularExpressionError()
EndIf

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
hss
User
User
Posts: 69
Joined: Thu Mar 08, 2007 6:02 pm

Re: CreateRegularExpression: non-capturing group?

Post by hss »

fits - thanks.
hss
User
User
Posts: 69
Joined: Thu Mar 08, 2007 6:02 pm

Re: CreateRegularExpression: non-capturing group?

Post by hss »

Code: Select all

(?<=<file>)((.*?)(?=<))
Post Reply