Page 1 of 1

CreateRegularExpression: non-capturing group?

Posted: Mon Nov 04, 2013 7:24 pm
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

Re: CreateRegularExpression: non-capturing group?

Posted: Mon Nov 04, 2013 8:20 pm
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

Re: CreateRegularExpression: non-capturing group?

Posted: Tue Nov 05, 2013 11:41 am
by hss
fits - thanks.

Re: CreateRegularExpression: non-capturing group?

Posted: Tue Nov 05, 2013 12:19 pm
by hss

Code: Select all

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