diff --git a/documentation/conf.py b/documentation/conf.py
index 48d28a686807..313cabec05bb 100644
--- a/documentation/conf.py
+++ b/documentation/conf.py
@@ -242,4 +242,30 @@ intersphinx_mapping = {
 # -- sphinx_copybutton configuration -----------------------------------------
 
 # sphinx-copybutton configuration
-copybutton_prompt_text = "$ "
+# This governs the copy button only. A mouse selection is a separate
+# mechanism and takes whatever the theme leaves selectable, which is the
+# command and its output; Sphinx already excludes the prompt itself.
+#
+# It also only reaches a block the console lexer read, since that is what
+# marks a prompt as a prompt.
+#
+# Strip the prompt from a copied line wherever the prompt cannot be
+# confused with content. The pattern is not scoped to console blocks, so
+# every alternative has to stay safe inside a BitBake or configuration
+# example as well; measured over the built manuals, each one matches only
+# lines the lexer itself marks as a prompt.
+#
+# A bare "#" is deliberately absent. It opens a root prompt, a comment and
+# a line of program output alike, and nothing distinguishes them - which is
+# why the root prompts are given a preamble before this is switched on.
+copybutton_prompt_text = "|".join((
+    r"^(?:\S+[@:]\S*)?\$\s+",   # "$ ", and "user@host:~$ "
+    r"^\S+[@:]\S*#\s+",         # "root@qemux86-64:~# ", a root prompt
+    r"^[A-Za-z]:\\[^>]*>\s*",   # "C:\WINDOWS\system32>", cmd.exe
+    r"^DISKPART>\s*",           # diskpart prints a prompt of its own
+    r"^pydevshell>\s+",         # bitbake -c pydevshell
+))
+copybutton_prompt_is_regexp = True
+copybutton_only_copy_prompt_lines = True
+copybutton_remove_prompts = True
+copybutton_line_continuation_character = "\\"
