RegExp to support for Grouping

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

RegExp to support for Grouping

Post 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...
User avatar
NicknameFJ
User
User
Posts: 90
Joined: Tue Mar 17, 2009 6:36 pm
Location: Germany

Re: RegExp to support for Grouping

Post 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
PS: Sorry for my weird english, but english is not my native language.



Image
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: RegExp to support for Grouping

Post by luis »

Yes this would be really useful. I wonder why does not already work anyway.
"Have you tried turning it off and on again ?"
A little PureBasic review
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: RegExp to support for Grouping

Post 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.
bye,
Daniel
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: RegExp to support for Grouping

Post 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
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: RegExp to support for Grouping

Post 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.
bye,
Daniel
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: RegExp to support for Grouping

Post 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
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: RegExp to support for Grouping

Post 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.
bye,
Daniel
User avatar
NicknameFJ
User
User
Posts: 90
Joined: Tue Mar 17, 2009 6:36 pm
Location: Germany

Re: RegExp to support for Grouping

Post 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
PS: Sorry for my weird english, but english is not my native language.



Image
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: RegExp to support for Grouping

Post 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.
Post Reply