Using Find and Replace

From NeoWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 13:34, 19 September 2007 (edit)
Lorinda (Talk | contribs)
m (Parentheses, etc. - just a little polish)
← Previous diff
Revision as of 07:17, 24 October 2007 (edit) (undo)
Jgd (Talk | contribs)
(Changing the style of all occurrences of a string - add Click on Replace All)
Next diff →
Line 61: Line 61:
==Changing the style of all occurrences of a string == ==Changing the style of all occurrences of a string ==
*To change the character formatting of all occurrences of a string, type that string in the search field and then in the replace field. Click on {{button|More Options}} and then {{button|Format}}. Set the {{Section|Font}} and {{Section|Font Effects}} as desired. *To change the character formatting of all occurrences of a string, type that string in the search field and then in the replace field. Click on {{button|More Options}} and then {{button|Format}}. Set the {{Section|Font}} and {{Section|Font Effects}} as desired.
 +*Click on {{button|Replace All}}.
==Parentheses, etc.== ==Parentheses, etc.==

Revision as of 07:17, 24 October 2007

OpenOffice.org and thus NeoOffice use a somewhat convoluted Find-and-Replace syntax. This page will hopefully demystify some of the commonly-used commands.

  • NeoOffice Help: Search for "replacing" or "regular expressions" (without quotes) in the Find tab of NeoOffice Help for more detailed info
  • Trinity threads on the subject: [1], [2], [3], [4]
  • Iannz Find & Replace Macro: http://homepages.paradise.net.nz/hillview/OOo/IannzFindReplace.sxw
  • Chapter two of the NeoOffice 2.x User Guide contains useful information about Find and Replace. (Note that this is a direct download link)
  • The Find and Replace section of the OpenOffice.org 2.x Migration Guide pdf (2.3 MB) also contains a useful chart comparing Find and Replace in Microsoft Office and OpenOffice.org.

Contents

Regular Expressions

  • Search and replace of formatting characters, such as returns (paragraph ends) and tabs can only be done by using the regular expression feature. You can't paste these characters into the search and replace fields.
  • Click on More Options in the Find & Replace dialog and check the Regular expressions box, then fill the codes required. These are given in the online help, but the explanations are not very clear.

N.B All the regular expressions are given between quotes. These quotes must not be entered in the search and replace fields.

Non Printing Characters

  • Line breaks
  • To find a line break, type "\n" in the search field.
If "\n" is entered in the replace field, it means paragraph end.
  • To change a line break into a paragraph break, enter "\n" in both search and replace fields.
  • Paragraph ends
  • To find a paragraph break, type "$" in the search field, be aware that "$^$" does not find adjacent empty paragraphs - it returns no matches. But any text$ finds and selects occurrences of any text at the end of lines, without selecting the end-of-line character itself.
  • To delete the empty paragraphs, type "^$" in the search field and leave empty the replace field.
  • There is no way in the Find and Replace window to replace two returns; Iannz's Find & Replace Macro will do this.
  • yoxi contributes the following macro useful for reformatting text where every line ends with a return (plain text to proper paragraphs): [5]
  • Line starts
  • To find the first character of a new line (or paragraph), type "^." in the search field.
  • Spaces
  • To find spaces, enter a space (with the space bar) in the search field (i.e. you don't need to use a regular expression) . That finds unique and multiple spaces.
  • To replace multiple spaces with a unique one, however, you do have to use regular expressions. Type " +" (space followed by a + sign), or " *" ( space followed by a * sign), or "[:space:]+" or "[:space:]*" in the search field and type " " (a space) in the replace field.
  • To delete the spaces at the end of lines, type " +$" in the search field and leave the replace field empty.
  • Tabs
  • To find tabs, type "\t" in the search field . It's the same expression in the replace field.
  • To insert a tab at the beginning of a line, type "^." in the search field and "\t&" in the replace field.
  • To insert a tab at the beginning of each paragraph, type "$" in the search field and "\n\ t" in the replace field.

Special characters

  • The "." (dot).
  • That character means any character except a line or a paragraph end.
  • The "&" character.
  • That character means "the string which has been found with the search criteria you used". For example, type "test" in the search field and "new &" in the replace field. The string "test" is replaced with "new test" in the document.
  • If you want to get the "&" character in your text, you have to type a backslash "\" in front of it.
For example, if you want to replace "John & Jack" with "Peter & Paul", you must enter "John & Jack" in the search field and "Peter \& Paul" in the replace field.
  • The quantifiers "*", "+", and "?".
  • The "*" character finds zero or more occurrences of the character in front of it.
"ab*c" finds "ac", "abc", "abbc", etc.
  • The "+" character finds one or more occurrences of the character in front of it.
"ab+c" finds "abc", "abbc", etc.
  • The "?" character finds zero or one occurrence of the character in front of it.
"ab?c" finds "ac" and "abc", but doesn't find "abbc".

Changing the style of all occurrences of a string

  • To change the character formatting of all occurrences of a string, type that string in the search field and then in the replace field. Click on More Options and then Format. Set the Font and Font Effects as desired.
  • Click on Replace All.

Parentheses, etc.

  • To find expressions in parentheses, including the parentheses, you can enter "\([a-z 0-9]*\)"

You will get a problem with the non ASCII characters, such as accented letters or ligatures in some languages. To solve that problem, enter "\([^\)]+\)" in the search field. This expression means : an opening parenthese followed by one or more characters, except a closing parenthese, followed by a closing parenthese.

  • To find the strings in braces or square brackets, proceed in the same way:

type "\{[^\}]+\}" or "\[[^\]]+\]" in the search field.

  • To italicize a string in parentheses, leaving the parentheses in regular style, follow these steps:
  • Find the strings in parentheses, as described above.
  • Press Cmd-I.
  • Click on Find All.
  • Type "\(" in the search field, click on Format in More Options. Choose the font and typeface: Italic.
  • Type "(" in the replace field, specifying the font and typeface: No italic.
  • Click on Replace All.
  • Do the same with the closing parenthese.

Sample Search

From amayze:

I recently complained in this post about the fact that NeoOffice regular expressions sometimes mean two different things depending where you use them, however this [in a Word .doc, "paragraph breaks" were actually represented in the file as line breaks within one giant paragraph (#$*&!@ Word...), so it's no wonder you ended up with one big mass of text after trying to strip out the whitespace] is exactly the instance when this is useful.

Try doing a search and replace.

  1. Click on "More Options..." and check the box by "Regular Expressions"
  2. Search for "\n" - which will match the line breaks in your document - and replace it with "\n" which will insert paragraph breaks in their place.
  3. Now change the search term to "^$" and the replace to "" (nothing) and you will be able to remove of the blank paragraphs in between your text.

Hope that helps.[6]

Behavior of the arrows at the end of the vertical scrollbar

The vertical scrollbar ends with three little icons that are, from top to bottom: two litte black triangles pointing up, a small blue ball and two little black triangles pointing down. Usually icons with the double triangles are used to go to Previous Page and to go to Next page
When you use Search and Replace, the two icons take different meanings: icon with triangles pointing up mean Continue search backwards, while icon with triangles pointing down means Continue search forward.
To go back to the normal behavior of these two icons you have to click on the icon representing the small blue ball; it will show a window called Navigation and there you have to click on Page icon.


This article in other languages: Français Italiano Español
Personal tools