in reply to Re^3: Tags in TK Text widgets
in thread Tags in TK Text widgets

I tried replacing the newlines, but I'm having a problem, it doesn't do what I expect. Because I want the replace to appear in the text box I tried:

$ts_box->FindAndReplaceAll(-regexp, -nocase, "[\n]", "%");
which appeared to have no effect, so as a sanity check I tried:
$ts_box->FindAndReplaceAll(-regexp, -nocase, "[+]", "%");
which works and replaces all the '+' chars with '%' chars. What am I doing wrong to stop \n matching?

Replies are listed 'Best First'.
Re^5: Tags in TK Text widgets
by hippo (Archbishop) on Aug 17, 2024 at 15:11 UTC

    I don't use Tk, but to me it looks like a problem of using double quotes where you should be using single quotes. eg. try $ts_box->FindAndReplaceAll(-regexp, -nocase, '[\n]', '%');

    I expect you don't need the square brackets either, FWIW.


    🦛

      Unfortunately that didn't make any difference and neither did leaving out the square brackets.

      I seem to remember there is something special about trying to match \n because matches are line based and \n is after the end of the match range or something weird like that.