Alternative Find and Replace dialog box for Writer

Extensions to the standard Find and Replace dialog box of Writer:

Tip to set up keyboard shortcuts for frequent use:

  1. Open the dialog Tools > Customize… > Keyboard
  2. In the Category field, navigate to Application Macros > My Macros > AltSearch > AltSearch
  3. In the Function field, select and assign the following (suggested) shortcuts using the Assign button:

You can also assign shortcuts directly from the AltSearch dialog box - see Batch mode


Main dialog box of AltSearch
AltSearch main dialog box

 

The Listbox menus (above the search string input field)

They contain frequently used or complicated regular expressions or search parameters that can be used in the search field. After choosing an entry, the corresponding parameters are transferred to the input field (or to both the search and replace fields if the second one is specified). These may be inserted in several ways: before or after the cursor or replacing the text in the input box. At the same time, the “Regular expressions” checkbox must be ticked.

Searching

List box “Regular

This box contains some helpful regular expressions. They are described in the LibreOffice Help searching for List of Regular Expressions

Limitation: The syntax used for regular expressions is not fully equivalent to the one in Writer. There are differences especially when using the wildcards *, +, ? or {n,n} just after subexpressions delimited by parentheses ().

For example (Mi)?ster will not be found, however, when using Count the actual count will be returned.

Furthermore, when subexpressions like (.*)any or (.+)any are searched for, the shortest occurrence is matched, where it would normally be the longest match. If it is necessary to preserve compatibility, you can delimit the whole search expression with an extra pair of parentheses: ((Mi)?ster). But this will, of course, lose you the chance to cite the subexpression in the replace expression as a reference, i.e. \# where # is a reference number (max. 9) of the subexpressions. Besides, it is not possible to use a reference on a subexpression (determined by parentheses ()) both for the searched and the replaced expression at the same time. See also subexpressions.

Other special wildcard parameters:

\l - represents any alphabetic character; same as [:alpha:].

\p - represents the paragraph termination sign,

in contrast to the ICU standard, $ also represents an empty paragraph. It is possible to use wildcards such as +, *, or {min,max} with $.

\p{1,} - will find the next end of paragraph followed by an unlimited block of empty paragraphs. Same as \p*.

\p{2,4} - will find the next end of paragraph followed by at least one and at most three empty paragraphs, i.e. a total of 2-4 paragraphs one after each other.

Limitation: Slow when used separately. Sometimes there are problems when searching backwards.

\xhhhh - represents the hexadecimal code for a character, e.g. \x0A is the code for a line break.

\#ddddd - represents the decimal code of a character

If the next character is not a digit, it is not necessary to keep of all 5 positions of ddddd. Otherwise it is necessary to fill in zeros from the left.

\c - represents a manual column break

Limitation: Slow when used separately.

\m - represents a manual page break

Limitation: Slow when used separately. If subexpression () is used, the parameter \m must be at the start of the search string, and it must not be alone: i.e. \m(…) is valid, but (…)\m is not.

\s - represents any space: normal space, non-breaking space, tab character or manual line break. Same as [\xA0\x9\xA]

\S - represents a non-breaking space (\x00A0 or \#160)

List box “Extended

[::BigBlock::] - searches for a block of paragraphs (of unlimited length) delimited by some known text:

start[::BigBlock::]end – at first, start is searched for and when it is found, end is searched for. If both are found, the whole block between them is selected.

In the replace string you can use the parameters \b, & or \e for inserting the contents of start, found block of paragraphs, or end, respectively.

Limitation: In the initial and final strings you cannot use the || sign for multiple searching and replacing (see below)

[::Grow n1,n2::] - the found block of text will be expanded by n1 characters to the left and n2 characters to the right

[::Grow -1,-1::]text - if the word text exists in the text then it will be found, but only the string ex will be selected.

Limitation: it is always necessary to use [::Grow… at the beginning of the search string and put the search expression after it. If n1 or n2 are negative values, then (depending on size and content of the search expression) the next search may cyclically find the same place.

text1||text2||text3||… - multiple search and replace operations in one step

Add the sign || to the end of the search and replace expressions to delimit partial searches and replacements.

Search for: text1||text2||text3
Replace: neco1||neco2||neco3.
This will search for text1 and it will be replaced by neco1, then the search continues for text2 which will be replaced by neco2, etc.

Limitation: you cannot use the parameter [::BigBlock::] with ||, nor can you use subexpressions.

Searching for Objects

[::Comment::] - searches comments (yellow balloons) according to their contents

[::Comment::] - will find the next comment

[::Comment::]pozn. - will find any comment containing the substring pozn.

Limitation: you can only search for substrings in the comments - you cannot use full regular expressions.

[::Field::] - searches text fields according to their contents.

[::Field::] - will find any normal text fields

[::Field::]obsah will find text fields in the document that display the text obsah

Limitation: the same as for [::Comment::]; see above. Besides, any special field (e.g. hidden) cannot be found.

[::TextFrame::] - searches text frames according to their name

[::TextFrame::] - will find any text frame

[::TextFrame::]rám1 - will find text frames containing the substring rám1 in their name

Limitations:

  1. When using the Find button, you will find the next text frame only if the frame is selected or if the cursor is inside the frame. If the cursor is a long way away in the text, then the first text frame from the internal list of frames inside the document is found.
    Warning: The option “Current selection only” currently doesn’t work.
  2. As a consequence of the previous point, the use of the Replace button is very limited.
  3. The order of searching unfortunately matches (I hope only provisionally) the order in which the text frames have been inserted into the document and not the order within the page(s) of the document from the start to the end.
  4. You can search only for a substring in the name of the frame - you cannot use full regular expressions.

Find all and Replace all are fully functional, including when used with the option “Current selection only”

[::Picture::] - searches pictures according to their name

[::Picture::] - will find any picture

[::Picture::]obr1 - will find pictures containing the substring obr1 in their name

[::Picture::]\text - will find substring text inside pictures Title text.

[::Picture::]\ - will find all pictures with empty Title text.

Limitation: the same as for [::TextFrame::]; see above.

[::TextTable::] - searching tables according to their name

[::TextTable::] - will find any table

[::TextTable::]tab1 - will find any table containing substring tab1 in its name

Limitation: the same as for [::TextFrame::]; see above.

[::Footnote::] - searches footnotes (FN)

[::Footnote::] will find the anchor of any FN

[::Footnote::]5 will find the anchor of a FN whose anchor contains the substring 5

[::Footnote::]\text will find the anchor of FN whose text contains the substring text. If the button Find all is used, the text of all FNs that contain the substring text will be selected.

Using [::Footnote::]\ with the button Find all, the text of all FNs will be selected (handy for assigning a paragraph style to all FNs at once)

[::Endnote::] - searches endnotes

Use of parameters and limitations are the same as for [::Footnote::]; see above.

[::ReferenceMark::] - searches for the target marker of cross-references

[::ReferenceMark::] will find any text set as a reference marker

[::ReferenceMark::]text will find any text set as a reference marker that contains substring text

[::ReferenceMark::]\ref1 will find any text set as a reference marker whose name contains the substring ref1

[::ReferenceMark::]\\ will find any text set as a reference marker whose text is empty

[::Reference::] - searches for text fields (cross-reference) by their markers

[::Reference::] will find all text fields of the cross-reference type

[::Reference::]above will find cross-references that contain the substring above

[::Reference::]\ref1 will find cross-references whose name contain the substring ref1

[::Reference::]\\ will find cross-references whose text is empty

If Reference is chosen from the list box “Extended” and at the same time the cursor is positioned in a text that is a Reference mark, then the corresponding source name will be automatically added to the “Search for” input box and it is possible to search for it immediately.

[::Bookmark::] - searches for Bookmarks

[::Bookmark::] will find place in the text or a block of text marked as bookmark

[::Bookmark::]text will find text if it is inside a text block who is marked as bookmark

[::Bookmark::]\RefHeading will find a place in the text or a block of text marked as bookmark only when the name of the bookmark contains substring RefHeading (searches substring in names of bookmarks)

List box “Properties

This enables searching according to the properties (attributes) of strings and their values.
The search entry must begin with the string [:::, followed by the name of the property. If there is more than one property, names can be separated using |, ie the sign of piping and must end with the characters ::]. After that, you can optionally set some specific string to be searched for. Then you can set the optional text to be searched for. On the contrary, if you need to search for the value of the property, then you have to use this kind of syntax: name=value.

The list of text attributes and their values, which can be used to search for in the current selection, can be loaded by using the Properties button: data are shown in the dropdown menu which appears below this button.
You can search for many attributes of characters (font type, size, background color, character/paragraph styles etc…)

Below you can find a list of these attributes/properties:

[:::CharFontName=Courier::] - search for characters using font type Courier in the selected block of text.

[:::CharFontHeight=24::] - search for characters with a 24 pt size in the selected block of text.

[:::CharBackColor=&HFE1410::] - search for characters with a background color which is something like red and whose RGB hex code is exactly FE1410 in the selected block of text.

The same color has an RGB (254,20,16) decimal code. This is also the same to say that its identification number is the result of the following mathematical operation:
(256*256*254) + (256*20) + 16 = 16651280
So you can find the background color also by using the expression:

[:::CharBackColor=NNNNNNNN::] where NNNNNNNN should be substituted by 16651280 in the previous example.

[:::ParaStyleName::] - searches for paragraph style

[:::ParaStyleName=::] will find all whole paragraphs with paragraph style different from the Default style

[:::ParaStyleName=Example::] will find whole paragraph with paragraph style Example

[:::ParaStyleName=Example::] something will find text something if it is formatted through paragraph style Example

Limitation: It doesn’t find some parts of the text with zero length, for example an empty paragraph. Besides, it can not simultaneously combine with other text properties.

[:::CharStyleName::] - searches for character style

[:::CharStyleName=::] will find part of the text with character style different from the Default style

[:::CharStyleName=Example::] will find part of the text with character style Example

[:::CharStyleName=Example::] something will find text something if it is formatted through character style Example

Limitation: It works just ahead - Backward switch does not work (message: not found).
Not find some parts of the text with zero length, for example, an empty paragraph.
It cannot simultaneously combine with other text properties.

[:::NumberingStyleName::] - searches for list style - similar use to searches for paragraph style, see above.

[:::HyperLinkURL::] - searches for text with the attribute HyperLinkURL

[:::HyperLinkURL::] will find all hyperlinks

[:::HyperLinkURL::]link will find the part of the hyperlink containing the text link.

[:::HyperLinkURL=file:///c:/pokus.odt::] will find a hyperlink in which the URL is the substring file:///c:/pokus.odt.

[:::HyperLinkURL=file:///c:/pokus.odt::]link will find part of a hyperlink in which the URL is the substring file:///c:/pokus.odt and in which the text contains the text link.

A list of available text attributes (with the values they have in the current selection) can be loaded using the button Pick properties: a dropdown menu appears next to that button.

Limitation: The search engine in Writer does not support all the existing paragraph and character properties. Not all combinations work as might be expected.

Replacing

List box “Replace

& \0 - both these parameters mean the same thing: on replacement they represent the whole found text

If the expression which is searched for uses [::BigBlock::], these parameters represent only the block of paragraphs between the start and end marks.

If the object which is searched for uses [::Comment::], [::Field::], [::TextFrame::], [::Picture::], or [::TextTable::], these parameters represent exactly these objects (which are inserted using the clipboard).

\b \e - If the expression which is searched for uses [::BigBlock::], these parameters represent content of the start and end marks.

Limitation: these cannot be used together with subexpressions ().

Subexpressions

\1 \2 \3 \4 \5 \6 \7 \8 \9 - content of subexpressions

If the search expression which was searched for uses parentheses (), \1 represents the content of the first pair of parentheses, \2 corresponds to the content of the second pair (), etc., up to \9, which corresponds to content of the 9th pair. Only 1st level of parentheses is valid; nested levels are ignored.

Example:
Using the expression (\d{1,2})\. *(\d{1,2})\. *\d{2,2}(\d{2,2}) to find dates in the format 01. 12. 2007 (yyyy.mm.dd) and replace them with dates in the format 07-12-01 (yy-mm-dd) using the replace expression \3-\2-\1.

If you need to switch off processing of subexpressions (e.g. to preserve compatibility with the regular expressions in standard ICU), you must put the whole search expression within an additional pair of parentheses. Then all other nesting levels of parentheses for replacement will be ignored.

Limitation: Using subexpressions is relatively slow and not fully compatible with Writer.

There is an in incompatibility with search wildcards placed immediately after a subexpression, such as (opak)*, which is caused by the principle of the sequential searching of sequential blocks of text (see here). In these cases the functions Count and Find all return the correct counts, but other functions (without switching to compatibility mode) will not find anything. In more complicated cases you will need to examine what happens and experiment to get the best results.

\p - inserts an empty paragraph

\t - inserts a tab (\x0009 \#9)

\s - inserts a non-breaking space (\x00A0 \#160)

\n - inserts a manual line break (\x000A \#10)

\c - inserts a manual column break before the found paragraph(s)

\m - inserts a manual page break before the found text

\M - inserts a manual page break after the found paragraph(s)

\r - removes manual column or page breaks in the found paragraph(s)

\xhhhh - inserts a character using the hexadecimal character code (as hhhh)

\#ddddd - inserts a character using the decimal character code (as ddddd).

\h{addressURL} - changes the found text to a hyperlink with the URL addressURL

\h{}, \h changes the found text to a hyperlink with a URL which is an empty string - this has the effect of deleting the hyperlink’s URL but the text of the hyperlink stays unchanged, of course.

\H{substr} - replaces the substring in the hyperlink’s URL. This should be used at the same time as searching using [:::HyperLinkURL=::]. If the expression was searched using for example [:::HyperLinkURL=substr::], only hyperlinks whose URLs includes the substring substr will be found. If \H{repl} is added in the replace expression, then the text substr will be found in the URL and replaced by repl.

\u - inserts in the replacing expression the URL address of the found text (if a hyperlink is found)

\P{Text} - sets up Paragraph style Text to the found paragraph(s)

The style is applied to the paragraph containing the text of the replaced expression. To set up the style to “Default”, use \P or \P{}. If this parameter is used a number of times with inserted paragraph(s), then the style will be changed with every new parameter and the last will be valid until the end of the paragraph. Example: If the expression was replaced using block1\P{Subtitle}\p block2\P{Heading 1}, then block1 will be inserted and the style Subtitle will be assigned to it. Afterwards a new paragraph with text block2 will be inserted and the style Heading 1 will be assigned to it.

\C{Quotation} - sets up the Character style Quotation to the found text

The style is applied to the whole text of the replaced expression. To set up to the “Default” style, use \C or \C{}. If this parameter is used a number of times, then the character style will be changed with every new parameter, and the last will be valid until the end of replacing expression. Example: If the expression was replaced using block1\C{Quotation}block2\C{Example}, then block1 will be inserted with the character style Quotation. Afterwards block2 will be inserted and the character style Example will be assigned to it.

\N{List 3} - sets up List style List 3 to the found paragraph(s)

Usage rules analogous to those for the parameter \P{} are applied. List style can be removed with \N or \N{}.

\D - sets up the default formatting to the found text, just like using Ctrl+Shift+Space. Usage rules analogous to those for the parameter \C{} are applied

\d - resets text attributes to default only in the place of use. Differently from \D it has no effect on the previously inserted text.

\F{New footnote} - inserts a new footnote that contains the text New footnote in the place of replacement. Inside the curly braces, the following parameters can be used: \i, \I, &, or \1

\E{New endnote} - inserts a new endnote in the place of replacement; analogous to \F

\B{ref1|text} - inserts the text text with the marker ref1 for a cross-reference. Inside the curly braces, the following parameters can be used: \i, \I, &, or \1

\L{0,0,ref1} - inserts a cross-reference (field) with the parameters 0,0 and the reference marker ref1

Meaning of numeric parameters:

\K{w,bookmark_name} - insert bookmark named bookmark_name.

First parameter is the mode of anchor

w - bookmark on whole selected text block

b - bookmark anchored at the start of text block

e - bookmark anchored at the end of text block

\K{}, \K - remove bookmark if is present in the selected text block. It removes only the bookmark; text block remains!

\K{w,new_name}\K - renames the bookmark - it must be found by using [::Bookmark::] or a place where the bookmark is already present

\o - inserts the text content of the found object. If the expression was searched for by using [::Comment::], [::Footnote::], [::Endnote::], [::TextFrame::], [::Picture::], or [::TextTable::], the text inside this object will be inserted. Tables come out with tabs between columns and paragraphs between rows.

If the expression was searched for by using [::Field::], [::Reference::] or [::ReferenceMark::] then the displayed text of the anchor or field will be inserted.

Limitation: The maximum size of the whole resulting text after converting a table is limited to 64 kB.

\O - inserts the name of the found object

If the expression was searched for by using:

\i - inserts the number of occurrences of the found object or the count of the occurrences of the text found. This works only if the button Replace all is used

\i{start,digit} - formatted counter. For example: \i{9,4} counts starting from 9, for 4 digits (0009, 0010, 0011…)

\I - inserts the number of the page on which the search expression was found

If redirection of the replace expression to another file (\R) is used (see below), the number of the page containing the starting position of the found text is inserted in the other file.

Limitation: this does not work correctly in footnotes, headers and footers.

\v - inserts the contents of the clipboard

\V - inserts contents of the clipboard as unformatted text

\f - preserves format

If & or \0 is used in the replace expression, itt will be achieved using the clipboard. If the found text contains text fields, notes, references etc., they will be preserved in their original state.

\R - redirects the replace expression to another text file

This option causes the replace expression to be inserted into new.odt file instead of replacing the found text. The original file will stay as it is, without any change. To enter the name of the output file, use the format \R{filename}. The name must have the accurate Writer window title format, including the text “ - LibreOffice Writer”. New records from this redirection are always added to the end of the file.

Example: if the searched expression was [:::HyperLinkURL::] and the replace expression is Link \i, page \I: & (URL: \u)\p\R, when you click the Replace all button all the hyperlinks found in original file will be listed in a new file in the form Link1, page 1: textOfHyperlink (URL: URLaddress) in separate paragraphs.

Link1, page 1: textOfHyperlink (URL: URLaddress)

Button and List box “Pick properties

Using the Pick properties button you can update the list of (some) properties and their values for the currently selected object. Then you can browse the list and choose one from the list box next to the button.

\A{properties=value} - sets in the replace expression the value of the specified property. Uses rules analogous to those for the parameter \C{} (see above).

For example if the property-value which was searched for is:
[:::CharBackColor=&HFF0000::], ie a red background color and you want to replace it with a blue background color,
then in the Replace box you must insert:
\A{CharBackColor=&H00FF00} (because the RGB hex code for blue is 00FF00).

Batch mode

 

Batch Mode
Batch mode dialog box

 

Batch mode enables saving and loading of some preset search and replace parameters. Several search and replace operations can be saved to a single sequence, and then quickly loaded and executed.

You can set all parameters and save them using the Save batch button. In the dialog box that is shown, you will be offered the name used for the last batch which you can rename. If you enter a name that already exists, you can choose whether the old content will be overwritten or preserved. In this case the new content will be appended to the end of the old file. If you decide to overwrite the old file, then you have to press the “Replace” button and the new procedure will be automatically saved. Together to the batch file it is also automatically saved the command “ReplaceAll” allowing you to subsequently execute the batch. You can also modify the content of the procedure by manually editing the batch rule file using the Modify button.

The button Batch >> switches to “Batch manager” dialog box, where you can run and edit batches. To go back to the search dialog, use the << Searching button.

All batch parameters are saved to the text file AltSearchScript.txt into the directory …/config/ in LibreOffice user profile, and you can open and edit it using the Edit button in the Batch manager dialog. For editing the text, the program Notepad is used by default, but you can set it to use any other text editor by editing the file AltSearchEditor.ini in the same directory. After manual changing and saving the file using the Batch manager you can refresh the list of batch names using the Refresh button. The syntax used in the file AltSearchScript.txt is described at the beginning of the same file, using UTF-8 encoding.

When you double-click on an item of the list, or click the Execute button, the chosen sequence will be loaded and the search and replace operations will be executed. When using batches on selections, I advise you to leave 1-2 empty paragraphs at the beginning and the end of the selection.

Transfer button is used for transferring the parameters of settings, searching, and replacing to the search dialog box without executing them. If the batch contains a sequence of several searches and replacements, only the last part of this sequence will be transferred.

Keyboard shortcuts

The button Key shortcut opens a dialog box that allows you to assign a keyboard shortcut to an existing batch.

 

Keyboard shortcuts
Dialog box to assign keyboard shortcuts

 

To use this button you need:

  1. Select the name of batch from the drop-down menu box
  2. If it is required, change the name of the Basic auxiliary subroutine
  3. Set the desired keyboard shortcut
  4. Press the button Assign

In order for the shortcut to work, at the time of assignment an auxiliary procedure is created in the Basic module Standard.AltSearchBatchs with a name that is adjusted according to the Basic syntax. This name is displayed in the second drop-down menu box of the dialog box. When this auxiliary procedure is run, the AltSearch dialog box will be opened and the specified batch is immediately executed. A correct behavior depends on the compliance of the batch name listed inside the procedure and the name of existing batch. If you change the name of a batch which had a shortcut key previously assigned, you need to re-assign a new key shortcut (the old auxiliary procedure to the original name can be deleted by selecting it in the second drop-down box and using the side button x). Any keyboard shortcut that is used in Writer can be released using the lower button x. So be careful not to remove inadvertently an important shortcut!

Multiple execute

 

Multiple execute
Multiple execute

 

A selected batch in the Batch manager dialog box can be applied to several currently opened text files at once:

In order to do that, you need to:

  1. Select Batch in the Batch manager dialog box
  2. Click on the button Multiple execute
  3. Select files for a multiple execution from the list using Ctrl + left button mouse click.
    WARNING: The list shows only the currently opened files of the "Writer" type.
  4. Press button Start for beginning the execution
    WARNING: while Multiple execute is running, please do nothing with Writer!

Selecting “Disable message” suppress messages about changes after each file is executed. Anyway, as soon as processing is over, the final report will be displayed.

Limitations

Known limitations are mostly mentioned within the description of individual parameters.

Generally applicable: