[Gambas-user] RegExp.Replace() question (was: sliderbox bug: Still respond to mouse wheel when its disabled)

Fernando Cabral fernandojosecabral at ...626...
Sat Apr 29 23:48:46 CEST 2017


Tobi, I was not aware and have been careless with the subject issue. Sorry.

As to the Regexp.Replace quirk, I found it out the hardest way: trying,
trying and trying.
Now I hope I have that knack of it. At least with the more basic
expressions.

Thank you.

- fernando

2017-04-29 8:48 GMT-03:00 Tobias Boege <taboege at ...626...>:

> On Fri, 28 Apr 2017, Fernando Cabral wrote:
> > Hi, gambas is new to me, but regex is not so new. But I am baffled with
> the
> > following result:
> >
> > str = "A#BB##CCC###"
> > print RegExp.Replace(str, "[#]+", ";")
> >     A;BB;;CCC;;;
> > str = "A#BB##CCC###"
> > print RegExp.Replace(str, "[#][#]*", ";")
> >     A;BB;;CCC;;;
> > str = "A#BB##CCC###"
> > print RegExp.Replace(str, "##**", ";")
> >     A;BB;;CCC;;;
> >
> > In my opinion, in every example above the result should be:
> > A;BB;CC
> > Nevertheless, gambas always displays A;BB;CCC;;;.
> >
> > Am I missing something,, or does gambas has a bug in this point?
> >
>
> We had this topic a few days ago [1]. When you use RegExp.Replace(),
> the greediness of all quantifiers is inverted. So when you use
>
>   "[#]+"
>
> under RegExp.Replace(), this has the same meaning as the expression
> (in PCRE syntax)
>
>   "[#]+?"
>
> matching lazily (or ungreedily) against the string, which explains
> the result you get. If you want greedy behaviour (what you expected),
> then you have to use ungreedy quantifiers:
>
>   Print RegExp.Replace("A#BB##CCC###", "[#]+?", ";")
>   Print RegExp.Replace("A#BB##CCC###", "[#][#]*?", ";")
>   Print RegExp.Replace("A#BB##CCC###", "##*?", ";")
>   ---
>   A;BB;CCC;
>   A;BB;CCC;
>   A;BB;CCC;
>
> Yes, admittedly it is strange behaviour of RegExp.Replace() to invert
> the greediness of all quantifiers and it was discovered just a few days
> ago. I don't know if it is going to be fixed though. I bet there was a
> rationale behind this setting, but we'll have to wait for a comment of
> Benoit who wrote the code.
>
> Regards,
> Tobi
>
> [1] https://sourceforge.net/p/gambas/mailman/message/35802891/
>
> PS: When you want to talk about a new topic, make a new thread and don't
>     compose your email by replying to an existing message from the mailing
>     list. Currently our conversation about RegExp.Replace() takes place
>     in a thread about a specific SliderBox bug, which makes it harder for
>     people in the future who are searching for this discussion.
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



-- 
Fernando Cabral
Blogue: http://fernandocabral.org
Twitter: http://twitter.com/fjcabral
e-mail: fernandojosecabral at ...626...
Facebook: f at ...3654...
Telegram: +55 (37) 99988-8868
Wickr ID: fernandocabral
WhatsApp: +55 (37) 99988-8868
Skype:  fernandojosecabral
Telefone fixo: +55 (37) 3521-2183
Telefone celular: +55 (37) 99988-8868

Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
nenhum político ou cientista poderá se gabar de nada.



More information about the User mailing list