How to clear unwanted characters from a cell?

Hello!
The characters allowed in eg. B3 are A to Z, 0 to 9 and “-” (hyphen)
Unwanted characters should just disappear.

Suppose the following text 'KR2000050-1 is in cell B3 ( " " at the beginning, should be filtered out)
I hope to get a clean result in cell C3
How should the formula be written?

1 Like

Use the REGEX() function (LibO V6.2 or higher).
See attached example:
disask117588_specialRegex.ods (13.3 KB)

See also:
https://www.regular-expressions.info/quickstart.html
The RegEx flavor used by LibO is:

Thank you! (this formula works REGEX(B3;"[^A-Z0-9\-]+"; ""; "g"))
I understand the first path [^A-Z0-9\-]+, but
I don’t understand the second and third parts of the REGEX instruction ""; "g")
What do these additions with RegEx?

Previously I used this instruction .: UPPER(TRIM(CLEAN(INDIRECT("Underlag." & "C" & ROW(C8)))))
But with regex I don’t need the instructions TRIM and CLEAN (If I understood correctly)

My instruction would then look like this: REGEX(UPPER(INDIRECT("Underlag." & "C" & ROW(C8)));"[^A-Z0-9\-]+"; ""; "g")
(If I understood correctly)

See the syntax for REGEX(); in particular the third and fourth arguments.

this one might be worth reading as well : How to remove single quote in front of numbers in a cell

An indicating apostrpohe needs to be typed at the beginning of a string into a cell being formatted to show a number if the string would otherwise be “recognised” as a number. In this case the apostrophe doesn’t become a character of the string and is only shown during editing and in the input line. How should this apply to the given case?

@Albireo: If you want additional help/instructions for a very special situation, you should attach an example file (.ods in this case).