Kate is not finding regular expressions for start or end of line?

I am new to using Kate, having used Notepad++ before switching to linux. I often have to append something to the start and end of every line on multiple files, and this had always been easy. Make sure regular expressions are checked, then find ^ or $, replace with the text I want to use, (frequently

)

When I switched to Kate, I find that it is not finding any matches, which is strange, as there are definitely several starts and ends of lines for it to find.

I have tried switching it to just searching the open file, and searching all open files, but nothing changes. Just “0 matches, (0 checked)”

p.s. Ignore that I am placing the opening

tag at the end of the line in the picture. I was bouncing between ^ and $ trying to get something to work.

Excuse me if I am missing something, but surely that is not how you would prepend or append stuff to a line, right?

You would do

^(.*)$

in the find text box, and

<p>\1</p>

(for example) in the replace box.

1 Like

I can replicate this when using the Search tab. $ is recognised as part of a regular expression (first screenshot), but not by itself as an entire regex (second screenshot):

Interestingly, if I start a search using Ctrl-F (as opposed to the Search tab), and put it in “Regular expression mode”, then $ by itself is recognised. (In the screenshot below, the search finds the four line endings and cycles between them.)

I’m using Kate 25.08.3.

2 Likes

Unrelated to this, but you can use multiple cursors to solve this problem.

  • Select All (Ctrl + A)
  • Alt + Shift + I → put cursors at the end of every line
  • Edit the lines however you want.
1 Like

Thank you. It appears that Kate has a much more thorough regular expression tool than I am used to from Notepad++, or at least than I had noticed, but that does come with a bit of a learning curve for me. Thank you for showing the proper way to do that. As the comment below from pg-tips stated, the ability to do it like you can from Ctrl+F is what I was used to, only needing to type the ^ or $ to find all the starts or ends of the line, then pressing replace all.

I do look forward to being able to condense it to one step, instead of two, (First start of line, then end of line.)

I am not by any means a regex expert. But I started using them as I learned to use them in Python, PERL and Badh tools like sed and grep. And they worked, so I assume Kate is just using the same set of rules.

In this case, and just in case the above solution is not clear, ^ represents the beginning of the line and $ the end (as you already know), .* is all characters, so ^.*$ means all characters on the line. Then the () serve to “remember” the bits you want to carry over to the substitution bit and number 1 to n from left to right.

Then you can recall them with \1, \2 … \n in the substitution part.

So

<p>\1</p>

in this case means substitute the pattern with <p>, then the content of the brackets (i.e. everything between the beginning and the end of the line, and then </p>.

1 Like

this seems like a bug to me.

i would expect regex to behave the same using either method

also, when using find (Ctrl+F) on my 23.08 version it does not insert the replacement string when using [Replace] , but it does insert the string when using [Replace All]

2 Likes