Retain leading 0 when using regular expression replace in calc

I have a file of UPC numbers, many of shich start with a 0 (zero), formatted as text and currently showing as an example: 0010034246

Some of the cells have a random newline character at the end, so I tried to do a replace (find \n; Replace with" " (space); regular expressions, current selection only), and it remmoved the newline properly, but the cell now contains 10034246 formatted as a number.

Is there a way to retain the text formatting and leading zeros?

Thanks,
Paul

I can replicate with 7.5.8.2 but not with 7.6.4.1 nor 24.0.2

In 7.5.8.2 I entered in the Replace field an En space (U+2002) and the cell kept its Text formatting with the leading 0 retained.

do they run in the same environment ? (OS, locales, …)

Version: 7.5.8.2 (X86_64) / LibreOffice Community (& parallel installed versions on same Windows computer and same settings).
Build ID: f718d63693263970429a68f568db6046aaa9df01
CPU threads: 8; OS: Windows 10.0 Build 22621; UI render: Skia/Raster; VCL: win
Locale: en-NZ (en_NZ); UI: en-GB
Calc: CL threaded

Might be related to Bug 38982 - Calc [EDITING, FORMATTING] find & replace causes default formatting to be applied to cells, undo working incorrectly

Though I don’t know why it would work in the later versions as it is still listed as NEW

Ernest,

My apologies for not including system data. Here is the environment:

Version: 7.3.7.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 4; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: en-CA (en_CA.UTF-8); UI: en-US
Ubuntu package version: 1:7.3.7-0ubuntu0.22.04.4
Calc: threaded

I have found a solution, if a bit of a cludge. Because cells containing muliple UPCs, such as example 9781593597238, 000022649010 removed the newline successfully, I assumed that LO already knows it’s text because of the comma. So where there was only 1 UPC I appended “, zero” to the column. then the remove newline worked and I ended up with 000022649010,zero, I then simply ignore values of “,zero” when evaluating. (find/Replace of “,zero” resulted in the leading zeros being removed.

https://help.libreoffice.org/latest/en-US/text/scalc/guide/text_numbers.html