Find and Replace with Regex is a problem with me

I don’t know what (deleted) has the developer group done with Libre Office, I have serious problems finding strings with simple regular expressions.

A simple Regex with ^ does not work, but this one $ does work.

I need to replace the start of the line with something and I just cannot do it.

I also tried ^(?<=.*), nothing happend.

I don’t think I am doing something wrong, is this a bug? Should I report it?
I appreciate your help.
LibreOffice Version: 20(Build:2)


Please take into account that this website is also accessed by children and young people.

replace the start of the line

Is this exactly one letter or one figure or one word or what else?
@JohnSUN’s answer can lead you to the right point but should be “refined” a little bit… :wink:

No thanks, ^(.*) matches everything that is in the first line. You can test it in
What I need to do is to put a single quote ' at the beginning of each row.
And sorry for the curses, But I don’t think I have said any.

See tdf#145774 and tdf#135538.

Ok people, thank you very much for your replies, a solution has already been marked.
The problem is indeed a Bug, and it’s detailed in the following bug:

What is actually happening is that Calc is returning “no matches” after a match that is of 0 length.
As ‘^’ will return a 0 length match, Calc will say that there’s no match, which is incorrect, because there is a match, it is just that is a beginning of string with zero length, but it’s a match.

Thank you.

If you meant “at the beginning of the line BEFORE SOMETHING” then must indicated this “something” both in the search string and in the replacement string. For example so: ^(.*) replace with '$1 (or ^.* with '& or any other)

1 Like

That’s not the solution ^(.*) actually matches everything in a first line. You can test it in
What I need to do is to put a single quote ' at the beginning of each row.
For example, when you put $ in find and replace you can put the quote ' at the end of each row.
$ works like a charm, but I don’t understand why ^ does not work.
I think it’s a bug. In visual studio code ^ works great in find and replace. You can try it.

Actually, where can I report that bug? Where can I report bugs for LibreOffice??

Bugs are reported via Bugzilla, but I guess you just didn’t get the concept of Writer and Calc.

While all editors works with lines (and I assume Visual Studio does the same) the word processors like Writer use the paragraph as a unit, wich is fitted between margins. So there is no concept of lines to be replaced.

^ is the beginning of a paragraph, $ the end of the paragraph.

Text in Calc behaves similiar, as the text us adapted to the current layout of the cell.

If you include manual line breaks chr(10) you have to find and replace these.

This is right, but the ( ) stores the found pattern for later reference. Replacing with '$1 therefore should give the desired result of a ’ before the content of the line.

Hi, thanks for your answer.
I’m not using manual line breaks in cells.
I already filed the bug in
^ should match beginnings of strings just like $ matches ends of strings in Calc, there’s no explanation as to why ^ is not working.
Besides, in previous versions ^ used to work as expected.
I will document here what the developers say after viewing my bug report. Thank you.

Thank you, JohnSUN wrote the solution but in that moment I didn’t understand what he was saying. It works well that way.
Anyways, The bug report is already filed in As the expression ‘^’ is a legal regular expression it should work just the same as ‘$’, which is working as expected.
Thank you.

EDIT by @LeroyG: tdf#145856

Actually the behaviour of $ is documented for calc:

And the part on writer clearly states “paragraph” not line so I guess it is difficult to change without breaking existing code if the topic lines vs paragraph is concerned

To make the non-working single ^ working may not break anything.

#145856 is the number of your bug report