3

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?

2
  • "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? Commented Mar 22, 2016 at 13:49
  • I 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! Commented Mar 22, 2016 at 14:14

2 Answers 2

4

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.

0
5

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.

4
  • Having 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. Commented Mar 22, 2016 at 14:09
  • 2 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 Commented Mar 22, 2016 at 14:16
  • Thanks for your answer. This one works, except it does not replace the space but puts the linebreak in front of it. Commented Mar 22, 2016 at 14:16
  • You must have put an extra space in the replacement string (the display with back-quotes is confusing). It works perfectly for me. Commented Mar 22, 2016 at 14:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.