Find & Replace Numbers with Decimal Points

Discuss the word processor

Find & Replace Numbers with Decimal Points

Postby shoeheel » Sat Jan 26, 2008 8:52 pm

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!
shoeheel
 
Posts: 4
Joined: Sat Jan 26, 2008 8:25 pm

Re: Find & Replace Numbers with Decimal Points

Postby floris v » Sat Jan 26, 2008 8:59 pm

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.
MS Windows Vista - AOO 4.0.1 - LibreOffice 4.1.0.4.
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
floris v
Moderator
 
Posts: 3029
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: Find & Replace Numbers with Decimal Points

Postby acknak » Sat Jan 26, 2008 10:01 pm

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.
AOO 4 • Linux • Fedora 17
User avatar
acknak
Moderator
 
Posts: 17420
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Find & Replace Numbers with Decimal Points

Postby JohnV » Sat Jan 26, 2008 10:25 pm

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.
JohnV
Volunteer
 
Posts: 1509
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Find & Replace Numbers with Decimal Points

Postby acknak » Sun Jan 27, 2008 12:29 am

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
AOO 4 • Linux • Fedora 17
User avatar
acknak
Moderator
 
Posts: 17420
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Find & Replace Numbers with Decimal Points

Postby JohnV » Sun Jan 27, 2008 7:13 pm

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.
JohnV
Volunteer
 
Posts: 1509
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Find & Replace Numbers with Decimal Points

Postby acknak » Sun Jan 27, 2008 11:45 pm

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.
AOO 4 • Linux • Fedora 17
User avatar
acknak
Moderator
 
Posts: 17420
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Find & Replace Numbers with Decimal Points

Postby shoeheel » Thu Jan 31, 2008 2:47 am

So geniuses, what's the answer? Why all the cryptic BS?
shoeheel
 
Posts: 4
Joined: Sat Jan 26, 2008 8:25 pm

Re: Find & Replace Numbers with Decimal Points

Postby floris v » Thu Jan 31, 2008 2:51 am

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:
MS Windows Vista - AOO 4.0.1 - LibreOffice 4.1.0.4.
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
floris v
Moderator
 
Posts: 3029
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: Find & Replace Numbers with Decimal Points

Postby Dave » Thu Jan 31, 2008 4:37 am

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.
Dave
 
Posts: 1011
Joined: Sun Dec 23, 2007 6:53 pm

Re: Find & Replace Numbers with Decimal Points

Postby shoeheel » Thu Jan 31, 2008 5:12 am

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.
shoeheel
 
Posts: 4
Joined: Sat Jan 26, 2008 8:25 pm

Re: Find & Replace Numbers with Decimal Points

Postby acknak » Thu Jan 31, 2008 7:15 am

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
AOO 4 • Linux • Fedora 17
User avatar
acknak
Moderator
 
Posts: 17420
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Find & Replace Numbers with Decimal Points

Postby shoeheel » Thu Jan 31, 2008 1:54 pm

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.
shoeheel
 
Posts: 4
Joined: Sat Jan 26, 2008 8:25 pm


Return to Writer

Who is online

Users browsing this forum: Grytpype and 35 guests