Making PCRE compatible or similar to other RegExps
Posted
#1
(In Topic #1459)
Regular

Their properties and methods behave different from Regexp in other famous languages. (PHP, javascript, etc)
I am not criticizing, just reporting facts and I offer a sugestion in the end that makes it compatible and a "real" findall method, you can call it allMatches method
RegExp.text is actually the "Match[0]" but is <COLOR color="#CC0000">not included</COLOR> in the Count value, making a bit confusing if the person didn't read the documentation carefully.
Checking Count=0 leads a beginner to think "Oh, there is no matches…" leaving the RegExp.Text that actually has Match[0]
findall can not be executed against the full pattern with some paretheses groups. It only works if we provide "subgroup pattern" to it.
For example:
Will find only the whole string, skipping subgroup match. But if the pattern is only <COLOR color="#0000BF">\w+</COLOR> it finds 4 tokens.
I wrote this peace of code that makes it similar to other languages.
Using the example above, this Function will return the full source matched AND all its submatches, with a real Count= 2 that is the whole + the submatch
Code (gambas)
- sx.Add(reg.text) ' <= Match 0
- i = 1
- sx.Add(reg[i].text)
- i += 1
- Return sx
<COLOR color="#0000BF">That could be added in future versions</COLOR>, an <COLOR color="#800000">allMatches</COLOR> method, please show this to Benoir.
Posted
Administrator

If you go to: https://lists.gambas-basic.org/ you will find the User list if you scroll down (see image).sergioabreu said
please show this to Benoir.
Subscribe and post your request there and your "please show this to Benoit." has magically happened. Who could have ever guessed that to be possible…
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
1 guest and 0 members have just viewed this.



