Re: Regular Expressions: find_replace_limit doesn't make all replacements

new topic     » goto parent     » topic index » view thread      » older message » newer message

Is this what you're looking for? It works fine for me. I also tested here: https://regex101.com/r/wWCCCJ/1

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 result = regex:find_replace_limit( pattern, string, `~\1`, 20 ) 
 
? equal( result, "~ 0.013AUD~ 0.00%~ 0.000AUD~ Sell~ 42~ 1~ 4.379MAUD~ -~ -0.00AUD~ -~ Energy Minerals\n" ) 
-- prints 1, strings are equal 

PS: Use the "raw" backtick strings when writing regular expressions to avoid escaping backslashes and help prevent errors.
PPS: Use the {{{ and }}} blocks when you want to format raw plain text in forum posts. I've edited them in for you above.

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu