[Solved] Find & Replace Numbers with Decimal Points

Discuss the word processor
Post Reply
shoeheel
Posts: 4
Joined: Sat Jan 26, 2008 8:25 pm

[Solved] Find & Replace Numbers with Decimal Points

Post by shoeheel »

How do I Find & Replace Numbers with Decimal Points? For example, I wanted to replace "3.9", "4.0", "2.2", etc. with the word "Private". In the "Search for" section, I tried "*.*" (minus the quotes) with the "Regular expressions" box checked, but it didn't work. Thanks!
Last edited by Hagar Delest on Sun Mar 19, 2017 1:28 pm, edited 1 time in total.
Reason: tagged [Solved].
User avatar
floris v
Volunteer
Posts: 4422
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: Find & Replace Numbers with Decimal Points

Post by floris v »

Take a good look at the list of regular expressions in the Help that comes with OOo. Regular expressions just aren't as simple as in the good old days of DOS with just * and ?. Hint: [a-z] will catch any letter.
OpenOffice 4.1.11 on Ubuntu; LibreOffice 6.4 on Linux Mint, LibreOffice 7.6.2.1 on Ubuntu
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Find & Replace Numbers with Decimal Points

Post by acknak »

Search for: -?[0-9.]+ Oops: better to use JohnV's suggestion below.
Replace with: Private
Options:
Regular expressions = Yes
Search In: Values

You were close: .*\..* should work (but doesn't for some reason).

As floris_v suggested, check the help (or try here: Regular Expressions in Calc [OOo wiki]). A period is special and means "any single character", so ".*" means "any character, any number of times".
Last edited by acknak on Sun Jan 27, 2008 12:31 am, edited 1 time in total.
Reason: Added note.
AOO4/LO5 • Linux • Fedora 23
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Find & Replace Numbers with Decimal Points

Post by JohnV »

Here's another one with a little explanation.
Search = [0-9]*\.[0-9]*

With regular expressions "." means any single character and "*" means any number of whatever precedes it so ".*" would find all characters in all cells.

You need to find a decimal point and need to indicate that and not any character. To do so you escape it with "\" which means the single character following it should be read literally. Hence the "\." above.
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Find & Replace Numbers with Decimal Points

Post by acknak »

Ok, I see part of the problem. I was searching integer data values that were formatted to display decimal points. My pattern worked because it doesn't actually require a decimal point! Oops.

The online help confirms that searching the values does not search the displayed values, it searches... what? I don't really know. It seems to be the value according to some internal default numeric format.

E.g. your pattern will match a time, displayed as HH:MM (i.e. no visible decimal point![*]), I guess because the internal value is a decimal number.

It seems very odd to me that the search is not using the displayed value as the search target.

[*] The actual cell format is Number > General; the result is displayed as HH:MM. If the time value is zero, it doesn't match. If the format is actually HH:MM, it doesn't match. Very weird.
Last edited by acknak on Sun Jan 27, 2008 12:37 am, edited 1 time in total.
Reason: Added note
AOO4/LO5 • Linux • Fedora 23
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Find & Replace Numbers with Decimal Points

Post by JohnV »

acknak,

You are approaching this problem as though we are in a spreadsheet but the OP posted in the Writer forum. Another been there, done that for me.

I don't think it makes much difference in setting up the regular expression but number display formats and time values aren't issues in Writer.
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Find & Replace Numbers with Decimal Points

Post by acknak »

Oops. I guess that's what I get for working through all new posts at once, rather than one forum at a time.

Urgh. Thanks for the clue--sorry for the noise.
AOO4/LO5 • Linux • Fedora 23
shoeheel
Posts: 4
Joined: Sat Jan 26, 2008 8:25 pm

Re: Find & Replace Numbers with Decimal Points

Post by shoeheel »

So geniuses, what's the answer? Why all the cryptic BS?
User avatar
floris v
Volunteer
Posts: 4422
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: Find & Replace Numbers with Decimal Points

Post by floris v »

These people are offering a way to get your stuff sorted for you at no expense. You can at least make the effort to understand what they're telling you. I like to throw around with abbreviations like BS in other forums, trust me ;) but this isn't the right place for using saucy language.

Try JohnV's hint, don't just whine. And RTFM. :roll:

Edit: when you aren't acquainted with regular expressions, they look like cryptic BS a lot. Be thankful this isn't perl, that's tons worse. :lol:
OpenOffice 4.1.11 on Ubuntu; LibreOffice 6.4 on Linux Mint, LibreOffice 7.6.2.1 on Ubuntu
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
Dave
Posts: 1011
Joined: Sun Dec 23, 2007 6:53 pm

Re: Find & Replace Numbers with Decimal Points

Post by Dave »

Perhaps he [she?] will understand this possible alternative:

Try using a second column, and then check out appropriate formulas for locating a decimal in the entry, then using a conditional IF() to decide whether to keep or replace with "Private" in the new column. Hide the old column for printing/viewing when done.

P.S. I've done a lot of minor programming at various levels. i never found time to learn the convolutions of regular expression. Getting too damned old, I guess, and having no pressing need. So I do understand people's reluctance. You shouldn't have ot be a programmer to use a word processor successfully.

David.
shoeheel
Posts: 4
Joined: Sat Jan 26, 2008 8:25 pm

Re: Find & Replace Numbers with Decimal Points

Post by shoeheel »

I still don't get it. I'm just an average joe or joann trying to use the darn program. I could give a rip about programming or perl or whatever gets your juices flowing. Did I land on the wrong forum? Is this forum only for the openoffice.org elite, that can't seem to give a simple answer to a simple question? Or do you guys even use Writer and have no idea what I'm talking about? Please point me to the non-elitist, non-technical, Writer forum where I can get my simple question answered simply. Thanks in advance.
Last edited by shoeheel on Thu Jan 31, 2008 1:56 pm, edited 1 time in total.
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Find & Replace Numbers with Decimal Points

Post by acknak »

All right, since I contributed a big chunk of the confusion, I'll lay it out for you:

Edit > Find & Replace
Search for: [0-9]+\.[0-9]+
Replace with: Private
Options > Regular expressions = Yes
AOO4/LO5 • Linux • Fedora 23
shoeheel
Posts: 4
Joined: Sat Jan 26, 2008 8:25 pm

Re: Find & Replace Numbers with Decimal Points

Post by shoeheel »

acknak wrote:All right, since I contributed a big chunk of the confusion, I'll lay it out for you:

Edit > Find & Replace
Search for: [0-9]+\.[0-9]+
Replace with: Private
Options > Regular expressions = Yes
THANK YOU! IT WORKED.
Post Reply