Why do Automator workflows fail to replace selected text with their actions’ output in Safari 14 (on macOS 11)?
I am not sure what exactly are you trying to accomplish, but I have an AppleScript code to replace characters and maybe it can be a good way for you to start. This solution works no matter the program because it uses GUI scripting, you just need to select the text and invoke the Service.
As you can see the code is changing all : for /; you can use it to adapt for your needs.
on run {}
    tell application &quot;System Events&quot;
        key code 8 using {command down} -- Cmd+C Copy text to clipboard
        delay 0.1
        set the new_path to (the clipboard as string)
        set save_location to my replace_chars(new_path, &quot;:&quot;, &quot;/&quot;)
        delay 0.1
        set the clipboard to save_location
        key code 9 using {command down} -- Cmd+V Paste clipboard back
    end tell
end run

on replace_chars(this_text, search_string, replacement_string)
    set AppleScript's text item delimiters to the search_string
    set the item_list to every text item of this_text
    set AppleScript's text item delimiters to the replacement_string
    set this_text to the item_list as string
    set AppleScript's text item delimiters to &quot;&quot;
    return this_text
end replace_chars