Page 1 of 1

RegExp to support for Grouping

Posted: Fri Aug 24, 2012 4:11 pm
by Kukulkan
Hello,

currently, PB is not able to use grouping in Regular Expressions. The underlying PCRE is able to do, but the PB interface simply does not support.

http://www.regular-expressions.info/brackets.html

Please add this!

Kukulkan

Example:

Code: Select all

If CreateRegularExpression(0, "Over (The)")

  Dim Result$(0)
  
  a = ExtractRegularExpression(0, "The Quick 15 Brown Fox Jumped Over The 30 Lazy Dogs.", result$())
  
  MessageRequester("Info", "Nb strings found: "+Str(a))
  
  For k=0 To a-1
    MessageRequester("Info", Result$(k))
  Next

Else
  MessageRequester("Error", RegularExpressionError())
EndIf
Normally it should return two results:
[0] => Over The
[1] => The

Sadly, PB returns only the first one and there is no way to get the second...

Re: RegExp to support for Grouping

Posted: Mon Aug 27, 2012 12:01 pm
by NicknameFJ
+1

Hallo Kukulkan,

I wish that PB can to this nativly too.

Maybe Fred will enable this in one of the next version of the compiler. I need this functionality in one of my projects, so up to now, I had to Import the LIB and call the function of the underliying PCRE Lib directly. From PB 4.60 to 4.61 it have been changed so I had to do the import with an leading "PB_". Take a look at here: http://www.purebasic.fr/english/viewtop ... hilit=pcre

Thanks to Danilo for his help in the german forum. See my posting there http://www.purebasic.fr/german/viewtopi ... =3&t=25124


Greetings

NicknameFJ

Re: RegExp to support for Grouping

Posted: Wed Sep 05, 2012 11:36 pm
by luis
Yes this would be really useful. I wonder why does not already work anyway.

Re: RegExp to support for Grouping

Posted: Thu Sep 06, 2012 5:58 am
by DarkDragon
You want brackets to be used for optional statements? Am I understanding you right? The official way to do it would be something like that "Over (The)?" (with questionmark), but not only "Over (The)" (without questionmark). :| Weird.

Re: RegExp to support for Grouping

Posted: Thu Sep 06, 2012 6:58 am
by Kukulkan
Hi DarkDragon,

I don't understand your questions. It does not matter if you are using the questionmark or not. PB does not support grouping and this is what we complain about (you can try if you like). You will find certain other posts regarding the same problem...

Kukulkan

Re: RegExp to support for Grouping

Posted: Thu Sep 06, 2012 6:33 pm
by DarkDragon
Kukulkan wrote:I don't understand your questions. It does not matter if you are using the questionmark or not.
Sure it does, but I've misunderstood your wanted results (I first thought you've meant "Over The" and "Over "). Some regular expression libraries react like you want it, but its different from the theoretical regular expression model. I think I see the reason why: you also want to extract single groups of a found result.

Re: RegExp to support for Grouping

Posted: Fri Sep 07, 2012 8:19 am
by Kukulkan
Hi,

I just wan't to use the RegularExpressions possibilities provided by the underlying PCRE module. It is just a question of implementing the interfaces to PureBasic. It is not a special function because most RegExp implementations offer grouping...

Kukulkan

Re: RegExp to support for Grouping

Posted: Fri Sep 07, 2012 5:34 pm
by DarkDragon
Kukulkan wrote:It is not a special function because most RegExp implementations offer grouping...
Yes, but normally not for extracing single groups, just for grouping conditions like this:
RegExp: "Over (A|The) [a-zA-Z0-9]+"
String: "The Quick 15 Brown Fox Jumped Over The 30 Lazy Dogs And Over A Cat."
Result:
- "Over The 30"
- "Over A Cat"

At least in theoretical information technology you get used to it.

Re: RegExp to support for Grouping

Posted: Sun Jun 23, 2013 9:41 am
by NicknameFJ
Hallo,

I made a procedure to handle the grouping results like ExtractRegularExpression() does.

Take a look at here: http://www.purebasic.fr/english/viewtop ... 09#p415709

I hope it can be helpfull for everyone.

NicknameFJ

Re: RegExp to support for Grouping

Posted: Mon Oct 07, 2013 12:36 am
by Tenaja
+1 for this feature to be native. I had to do it recently, and had to sort through quite a few forum posts and web searches to figure out what it was called.