Find & Replace - full text searches and replacing |
To perform full-text searching use the Edit > Find (F3) command and in the Find field of the displayed Find & Replace toolbar specify the data to search for. Clicking the Options button you can specify how the searched data should be treated: as a regular expression or as plain text string.
Selecting a range of cells limits the searching and replacing procedure to that range. Clicking a worksheet (any cell)
invalidates the active search range and searching is performed within the whole worksheet till a new selection is made.
Changing search/replace options or text strings also initiates a new search with the current (new) selection.
Searching is performed as follows:
There are three search modes that can be specified using the Options button menu:
Regular Expressions - the Find string is a data pattern based on the standard regular expression syntax. Some examples of regular expressions:
abc | finds cells containing (substrings) "abc" |
.bc | finds cells containing three character substrings consisting of any character followed by "bc" |
\Aabc | cell contents starting with "abc" |
abc\z | cell contents ending with "abc" |
\Aabc.*123\z | cell contents starting with "abc" and ending with "123" with any number of other characters in between |
abc\d\z | substrings ending with "abc" and one digit |
^a\d+ | cell contents containing a line that starts with "a" and at least one digit |
^a\d* | cell contents containing a line that starts with "a" and zero or more digits |
a\d*$ | cell contents containing a line that ends with "a" and zero or more digits |
[ab]+c | substrings "abc", "aabc", "abbabc" etc. and not "c" |
[ab]*c | substrings "abc", "aabc", "abbabc" etc. and "c" |
[^ab]+c | substrings ending with "c" and not containing "a" or "b" |
\w\d{2,3} | substrings consisting of one letter followed by 2 or 3 digits |
^ab\d{2,3}c | cell contents beginning with "ab", two or three digits and "c" |
abc|xyz | cells containing substrings "abc" or "xyz" |
(?=.*abc)(?=.*xyz) | matches cell contents contaning "abc" and "xyz" - logical AND |
\A\z | matches empty cells |
Using the Options button you can set two additional options:
Allow empty matches and Match case.
Empty matches occur for Regular Expression like a? or \A\z ,
which lets you search for e.g. empty cells with data blocks.
For more information, see PCRE regular expression syntax summary
The Replace string can contain:
(1) absolute references (by number) to capturing subpatterns, eg. \1, \2...
a capturing subpattern (or a "group") is a part of the pattern enclosed in () parenthesis.
(2) \l, \L, \u, \U literals to (binary) switch upper- and lower-case conversion
(3) \r, \n - 'line feed' and 'new line' literals (by default, Ctrl+Enter inserts the \r\n sequence into the text field).
(4) \s - a single space character.
Notes:
The regular expression tags can be easily inserted via the "RegEx" menu available in GS-Base
Examples:
Find pattern: | cat |
Replace string: | dog |
Result: | replaces "cat" with "dog" |
Find pattern: | \\ |
Replace string: | / |
Result: | replaces the "\" characters with "/" |
Find pattern: | \A\z |
Replace string: | NULL |
Result: | fills empty fields with sthe "NULL" strings |
Find pattern: | \ANULL\z |
Replace string: | |
Result: | if a field contains only the "NULL" string, deletes its contents |
Find pattern: | \b(\w+)(?:\W+\1\b)+ |
Replace string: | \1 |
Result: | removes duplicate words in fields |
Find pattern: | (\b\w)(\w*(\W+|\z)) |
Replace string: | \u\1\l\2 |
Result: | converts first letters in words to uppercase, other to lowercase |
Find pattern: | (\b\w)(\w*(\W+|\z)) |
Replace string: | \1 |
Result: | creates abbreviations consisting of first letters of words |
Find pattern: | (\b\w(\d*))(\w*(\W+|\z)) |
Replace string: | \1 |
Result: | creates abbreviations consisting of first letters of words, leaves full numbers |
Find pattern: | \b((\d{1,3}\.){3,3})\d{1,3}\b |
Replace string: | \1\* |
Result: | mask IP address (e.g. 11.12.13.114 to 11.12.13.*) |
Find pattern: | (\S*)(\s*)(\S*)(\s*)(\S*) |
Replace string: | \g5\g4\g3\g2\g1 |
Result: | reverses the order of up to first 3 words in fields |
Find pattern: | \R |
Replace string: | \s |
Result: | replaces line-breaks with spaces |
Find pattern: | ab+ |
Database field content: | abcdefaabb |
Replace string: | x |
Replacement result: | xcdefax |
Find pattern: | (.)a+\d{1,3} |
Database field content: | abc aa0102 |
Replace string: | \1 |
Replacement result: | abc 2 |
Find pattern: | (ab) |
Database field content: | abcdef ghijk abb123 |
Replace string: | \u\1\l\1xyz\s |
Replacement result: | ABabxyz cdef ghijk ABabxyz b123 |
Find pattern: | \R |
Database field content: | abc def ghi |
Replace string: | \s |
Replacement result: | abc def ghi |
The "Scripts" button on the "Find & Replace" toolbar can be used to performed quick mass text replacing in a given table.
Note: the "search" and "replace" strings entered in the window below must be entered like in a csv text file, so text containing commas, line breaks or quoting symbols must be in "" and inner quoting symbols must be doubled.