This is the idea: capture all non-space characters from the beginning of the line in the regex in one set of parenthesis, and then the first space, replacing with the first capture plus something instead of the space.
Here is that shown as a function you can run, rather than a direct command (easier to read and test):
(defun asjo-test-rr ()
(interactive)
(replace-regexp "^\\([^ ]+\\)\\( \\)" "\\1ABBA"))
Now, if you evaluate that function (put your cursor after the last parenthesis and go C-c C-e
), and then you go to a line, say your example:
What did the fox say?
and you type M-x asjo-test-rr
, the result is:
WhatABBAdid the fox say?
i.e. the first and only the first space has been replaced (with "ABBA").
You can of course type in the regexp and replacement string in the M-%
prompt, if you're not afraid of leaning toothpick syndrome.
(Although I've got to admit, I can't make it work doing that right now.)
this is a line
, you want to replace the space betweenthis
anda
, correct? Or only if the line starts with a space?this is a line
I would like to replace the space betweenthis
andis
.