Page 1 of 1

[Solved] Find & Replace Numbers with Decimal Points

Posted: Sat Jan 26, 2008 8:52 pm
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!

Re: Find & Replace Numbers with Decimal Points

Posted: Sat Jan 26, 2008 8:59 pm
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.

Re: Find & Replace Numbers with Decimal Points

Posted: Sat Jan 26, 2008 10:01 pm
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".

Re: Find & Replace Numbers with Decimal Points

Posted: Sat Jan 26, 2008 10:25 pm
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.

Re: Find & Replace Numbers with Decimal Points

Posted: Sun Jan 27, 2008 12:29 am
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.

Re: Find & Replace Numbers with Decimal Points

Posted: Sun Jan 27, 2008 7:13 pm
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.

Re: Find & Replace Numbers with Decimal Points

Posted: Sun Jan 27, 2008 11:45 pm
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.

Re: Find & Replace Numbers with Decimal Points

Posted: Thu Jan 31, 2008 2:47 am
by shoeheel
So geniuses, what's the answer? Why all the cryptic BS?

Re: Find & Replace Numbers with Decimal Points

Posted: Thu Jan 31, 2008 2:51 am
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:

Re: Find & Replace Numbers with Decimal Points

Posted: Thu Jan 31, 2008 4:37 am
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.

Re: Find & Replace Numbers with Decimal Points

Posted: Thu Jan 31, 2008 5:12 am
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.

Re: Find & Replace Numbers with Decimal Points

Posted: Thu Jan 31, 2008 7:15 am
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

Re: Find & Replace Numbers with Decimal Points

Posted: Thu Jan 31, 2008 1:54 pm
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.