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

One thing to do is to replace newlines with spaces in the validate sub.

sub validate_text { my $wstring = $ts_box->get("1.0", "end") =~ s/\s+/ /gr; $ts_box->delete('1.0', 'end'); $ts_box->insert('end', $wstring); $ts_box->tagAdd( 'badc', "1.$-[0]", "1.$+[0]" ) while $wstring =~ /[^A-Za-z0-9 \/.,=?*+]+/g; }

Some of the existing code has been slightly tightened up, just a little. :)

Replies are listed 'Best First'.
Re^4: Tags in TK Text widgets
by colintu (Acolyte) on Aug 18, 2024 at 17:56 UTC

    Ah, that is what I was trying to do using

    $ts_box->FindAndReplaceAll(-regexp, -nocase, "[\n]", " ");
    I tried several variations but although they matched a normal character I could never get it to match the \n

    Your tightening doesn't unfortunately apply to my actual code because there are other tests made in the bad check loop and $cnt is used for other stuff too. But thanks, I hadn't thought of pulling the string out of the widget to work on it and then putting it back.