Re: Regular Expressions: find_replace_limit doesn't make all replacements
- Posted by abuaf Feb 27, 2022
- 1220 views
Thanks greg for making a minimal test case. I've fixed your program to match my description (tabs not spaces on input), and fixed the error \s+(\s+) should be \s+(\S+) . Thanks for the heads up on backticks; no mention in the manual. What is the full details on them? Couldnt find much on the forum.
Used double quotes for your regex:find_replace_limit( pattern, string, `\1`, 20 ) since official eu 4.1 didnt accept this. After running, i get the error as i originally described where several replacement werent made, which may imply a serious error in find_replace_limit() / find_replace(). The output i get is (spaces is 1 tab);
~0.013AUD~0.00%~0.000AUD~Sell~42~1 4.379MAUD- -0.00AUD- Energy~Minerals
ie
0000 7e 30 2e 30 31 33 41 55 44 7e 30 2e 30 30 25 7e ~0.013AUD~0.00%~ 0010 30 2e 30 30 30 41 55 44 7e 53 65 6c 6c 7e 34 32 0.000AUD~Sell~42 0020 7e 31 09 34 2e 33 37 39 4d 41 55 44 7e 2d 09 2d ~1.4.379MAUD~-.- 0030 30 2e 30 30 41 55 44 7e 2d 09 45 6e 65 72 67 79 0.00AUD~-.Energy 0040 7e 4d 69 6e 65 72 61 6c 73 ~Minerals
Is this what you're looking for? It works fine for me. I also tested here: https://regex101.com/r/wWCCCJ/1
Errors as noted above, how can you enter tabs? but great link for quick testing. Users with super-sed can do this offline with;
sed -R -e "s/\s+(\S+)/~\1/g" 9.txt
include std/regex.e regex pattern = regex:new( `\s+(\S+)` ) -- ie a run of whitespace, and a capture of a run of non-whitespace. sequence string = "\t0.013AUD\t0.00%\t0.000AUD\tSell\t42\t1\t4.379MAUD\t-\t-0.00AUD\t-\tEnergy Minerals" puts(1, regex:find_replace_limit( pattern, string, "~\\1", 20 ) ) --ie like regex:split() to separate non-whitespace fields with a single '~` by compressing whitespace .