Original date:2022-02-28 11:04:51 Edited by: petelomax Subject: Re: Regular Expressions: find_replace_limit doesn't make all replacements

Not sure I can be that much help here, but I suspect it is length 1 rather than spaces vs. tabs:

include std/regex.e  
regex pattern = regex:new( `\s+(\S+)` )  
sequence string = " 0.013AUD 0.00% 0.000AUD Sell 42 1 4.379MAUD - -0.00AUD - Energy Minerals\n"  
sequence expctd = "~0.013AUD~0.00%~0.000AUD~Sell~42~1~4.379MAUD~-~-0.00AUD~-~Energy~Minerals\n" 
sequence result = regex:find_replace_limit( pattern, string, `~\1`, 20 )  
sequence reslt2 = regex:find_replace_limit( pattern, result, `~\1`, 20 )  
? equal( result, expctd )  
? equal( reslt2, expctd )  

Running the above on gives me

 0.013AUD 0.00% 0.000AUD Sell 42 1 4.379MAUD - -0.00AUD - Energy Minerals 
~0.013AUD~0.00%~0.000AUD~Sell~42~1 4.379MAUD~- -0.00AUD~- Energy~Minerals 

(The second shot works because you've got rid of all the length 1 previous substitutions, and that would still be true even if they wre back-to-back)

As above, no expert here, but the code you are looking for might be in right at the end,

start_from = ovector[rc] + rep_s->length; 

might perhaps be missing a -1 [and don't blame me if that goes into an infinite loop/make sure you test with a trailing space on the substitution]

HTH, Pete

Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu