Notepad++ - replace every first space of a line
Solution 1
You'll have to use RegEx to search and replace.
In the search, type: (.+?)[ ](.+)
In the Replace field, type: $1<br>$2
Make sure you are not searching for \r \n (its a checkbox) otherwise it will do a multi-line search.
Solution 2
It was a slightly tricky expression to find, but the following works:-
- Find:
^([^ ]*)
[this is^([^_]*)_
, showing space as underscore for display clarity] - Replace:
\1<br>
The search string is a line beginning with any number of non-space characters (marked as a subexpression) followed by a space (therefore the first on the line).
The replacement is the first subexpression (the leading non-spaces) followed by the string to replace the first space.
Related videos on Youtube
Trynox
Updated on September 18, 2022Comments
-
Trynox almost 2 years
I know there are a lot of these types of questions but I can not find a way to alter one of the existing solutions for my problem. My text file looks like this:
word<tab>word<space>words_with_spaces
I would like to replace every first space of each line with an html linebreak (br). Is there a simple way to do this?
-
Ƭᴇcʜιᴇ007 over 8 years"Is there a simple way to do this?" Yes, use RegEx (just like you tagged your question). What have you tried already? Where are you getting stuck exactly?
-
Trynox over 8 yearsI just recently started playing around with RegEx. In fact, yesterday. I got as far as searching for (.*?)[ ] and replacing with \1<br> and I was stuck at the "do it only once per line"-part. I got it thanks to the answers. Thanks for your response, too!
-
-
AFH over 8 yearsHaving seen LPChip's answer, I should add that the
. matches newline
setting does not affect my solution. I tested with it set and again with it clear. -
LPChip over 8 years2 different methods to achieve the same thing. I'll vote yours up as well as its just as good as my answer. :) I could've edited my answer to use the ^ operator so the multi-line search has no effect
-
Trynox over 8 yearsThanks for your answer. This one works, except it does not replace the space but puts the linebreak in front of it.
-
AFH over 8 yearsYou must have put an extra space in the replacement string (the display with back-quotes is confusing). It works perfectly for me.