Text Object - Find & Replace

The following Text object commands provide ways to find text inside an existing text object (and optionally replace it).

.containsString findString, [options] v2.1

Returns @true if the text object contains the given string. 

For more on this string comparison, and the valid options, see the rangeOfString command.

.hasPrefix prefix, [options] v2.1

Returns @true if the text object has the given prefix as a string. 

For more on how text is compared, and the valid options, see the rangeOfString command.

.hasSuffix suffix, [options] v2.1

Returns @true if the text object has the given suffix as a string. 

For more on how text is compared, and the valid options, see the rangeOfString command.

.rangeOfString findText, [options], [limitRange] v1.2

Searches the text object for the first occurrence of findText and returns a Range object describing the match. If no match was found, returns the @undefined value.

Unlike the find commands below this command only searches the characters strictly contained in the text object the command is used on. This means nested content, like table cells, is not searched.

The options argument modifies the behavior of the search and should be a string containing one or more of the following characters:

b

Search backwards (reverse).

i

The search is case insensitive. This option is independent from the comparison mode (the “n” and “s” options).

n

Sets the comparison mode to normal. In this mode logically equivalent character sequences are considered equal. For example, pre-composed sequences like ‘é’ (U+00E9) will match counterparts that use combining marks, eg: ‘e’ + Acute Accent (U+0301). This is the default mode.

r

Search backwards (reverse).

s

Sets the comparison mode to strict. In this mode exactly the same character values (Unicode code points) must be found.

If no options string (or an empty string) is given, then a forwards case-sensitive search is performed using the normal comparison mode.

If a limitRange is given, then only the characters within that Range object are searched. If no limiting range is provided the whole text object is searched.

.find findText, [options], [where] v1.2

Searches the text object for the first occurrence of findText and returns a TextSelection object that describes the match. This text selection may describe a text object that is different from the original. For example, the match may occur in a table cell that is contained/nested inside the original text. If no match is found the @undefined value is returned. 

The options argument modifies the behavior of the find operation and should be a string that contains one or more of the following characters:

*

Use the options currently set in the Find & Replace dialog. You can still add additional options using other characters.

$

For each capture in the find expression the captured text is stored in the macro variables $1, $2 ... $N, where N is the number of captures that occur. The whole match is stored in $0. 

This option does not work for “replace” or “find all” operations. If a capture was not present then the variable is set to the @undefined value.

This option will also make available named captures, which are a feature of PowerFind Pro expressions (regular expressions). For example, the regular expression (?<word>\w+) would assign the variable $word the text matched by \w+.

¢

Works exactly like the $ option as described above, but instead of capturing fully formatted text, only captures plain text strings. This is more efficient. Added in v2.1.1.

a

Find or replace all occurrences, instead of just the first one. With this option the command always returns an array of TextSelection objects. Even if no matches are found, an empty array is returned instead of @undefined.

b

Search backwards (reverse).

e

Treat findText as a PowerFind expressions.

E

Treat findText as a PowerFind Pro expression.

i

Case insensitive search.

m

Match case of found text before replacing. Added in v1.3.

r

Search backwards (reverse).

u

Find text is attribute sensitive.

U

Replacement text is attribute sensitive.

w

Only match whole words.

Each option character can be preceded by a minus/dash to turn off the given option. For example, “-i” makes the search case sensitive. By default the case insensitive and wrap around options are turned on, eg: the default options are “iW”.

The where argument is a string as described in the Find and Replace command. As of v3.0 the where argument could also be a Range object, specifying the range of characters within the single text object to search.

As of v2.0.5 the findText argument can also be a Style object instead of some text. If a style is given, then will match any text with that style applied.

.findAll findText, [options], [where] v1.2

A synonym for the find command (see above) with the ‘a’ (find all) option implied.

.findAndReplace findText, replaceText, [options], [where] v1.2

Searches the text object for the first occurrence of findText and replaces it with replaceText. This command returns a TextSelection object for the replaced text, or if no match was made the @undefined value. This text selection may describe a text object that is different from the original. For example, the match may occur in a table cell that is contained/nested inside the original text.

If the ‘a’ (replace all) option is specified, this command always returns an array of TextSelection objects. If no replacements were made, an empty array is returned.

The options and where arguments should be strings as described in the find command (see above).

As of v2.0.5 the findText argument can also be a Style object instead of some text. If a style is given, then will match any text with that style applied.

.replaceAll findText, replaceText, [options], [where] v1.2

A synonym for the findAndReplace command (see above) with the ‘a’ (replace all) option implied.

.rangeOfFirstMisspelledWordInRange checkRange, [language] v1.2

Returns a Range object for the first misspelled word intersecting the Range object given to check. If no misspelled word is found, returns the @undefined value. 

Normally the language applied to the text itself will control which spelling dictionary is used. If the text does not have a language (eg: it is an unformatted string) the system language will be used. Optionally a Language object may be specified to force searching for misspelled words using a particular dictionary.


Previous Chapter
Formatting & Layout
<<  index  >>
 
Next Chapter
Modifying Text