[Gambas-user] gb.pcre: RegExp.Replace() problem

Benoît Minisini gambas at ...1...
Sun Dec 21 15:36:11 CET 2014


Le 21/12/2014 14:33, Benoît Minisini a écrit :
> Le 20/12/2014 09:27, Tobias Boege a écrit :
>> Hi,
>>
>> attached is a script which essentially executes
>>
>>    Print RegExp.Replace(" * * a *", "^[ ]*\\*", "'")
>>
>> On my system the output is
>>
>>    '' a *
>>
>> which I don't understand. As the regular expression indicates I want only
>> the one match at the beginning of the line to be replaced. Not the second
>> one behind it. The "a" acts like a border, to see if the "^" is
>> completely
>> ignored -- but it isn't.
>>
>> The error seems to come from
>>
>> --8<-- [ trunk/gb.pcre/src/regexp.c
>> ]---------------------------------------
>> 389                         r.subject = &subject[offset];
>> --8<------------------------------------------------------------------------
>>
>>
>> I guess that this should prevent recursive (indefinite) substitutions
>> in the
>> replacement string... But if you ask me, the result of my script is
>> wrong.
>>
>> Regards,
>> Tobi
>>
>>
>
> Mmm. I'm far from being a regexp user, but I will try to check that...
>

I think you should not use Replace() for that. It tries to mimic the 
behaviour of Replace$(), i.e. finding each match and replace it, by 
going forward in the string.

Maybe could I add a special case for pattern beginning with "^", which 
then means "just replace once"?

-- 
Benoît Minisini




More information about the User mailing list