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.
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.)
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>.
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]