Please enable JavaScript to view this site.

R:BASE 11 Help

Navigation: How To (Forms, Reports, and more) > R:BASE Editor

Using Regular Expressions for Finding Text

Scroll Prev Top Next More

Regular expressions consist of patterns that can be used to search for variable forms of text. Without regular expressions, you must know the exact phrase for which to search; regular expressions allow you to find all text that follows a certain pattern. Even if the "Regular expressions" check box in the Find/Replace dialog is on, you can still search for exact phrases. In such a case, you have to remove the regular expression operators from the search criteria.

 

Syntax of Regular Expressions for Finding Text

Regular expressions generally consist of some constant text, and some restrictions or wildcards on the rest of the text. If you want to use one of these operators as literal text, you must precede the character with a backslash.

 

The following is a list of regular expressions used only for searching text. When searching text, you can also use regular expressions that are used for all types of operations.

 

Character

Meaning

\

Escape character. If you want to use the character '\' itself, you should use '\\'.

^

Line start

$

Line end

*

Character to the left of the asterisk in the expression should match 0 or more times. For example, 'be*' matches 'b', 'be' and 'bee'.

+

Character to the left of the plus sign in the expression should match 1 or more times. For example, 'be+' matches 'be' and 'bee' but not 'b'.

.

Matches any character.

[ ]

Any of the enclosed characters may match the target character. For example, '[ab]' matches 'a' and 'b'. '[0-9]' matches any digit.

[^]

None of the enclosed characters may match the target character. For example, '[^ab]' matches all characters except 'a' and 'b'. '[^0-9]' matches any non-digit character.

-

When used within a character class, represents a character range.

{}

Create a group. E.g. "{[0-9][0-9]}" is a group that is composed of 2 digits. The search string "{[0-9][0-9]}+" will find the first 8 digits in "123456789" because that is 4 pairs of 2 digits.

 

Examples

 

Example 01:

Find a line that starts with "A" and ends with "2":

Search criteria: ^A.*2$

“^A - Line must start with an A

“.*” - Zero or more characters (any character)

“2$” - Line must end with a 2

 

Search sample and result:

Abc-12 - Found

A2 - Found

1Abc-12 - Not found (line does not start with A)

Abc-123 - Not found (line does not end with 2)

 

Example 02:

Find text that contains the word "Plan," followed by optional space and a 4-digit number:

Search criteria: Plan *[0-9][0-9][0-9][0-9]

“Plan - The literal word ‘Plan’ must start the phrase

“ * - (space character followed by *) Zero or more space characters

“:d:d:d:d - Any four digits

 

Search sample and result:

My Plan1234 - Found

Plan 1234 - Found

My Plan 123a - Not found (only 3 digits follow Plan)

 

Example 03:

Find text that contains the characters ' [# ' but is not followed by a 1, 2, 3, 4, or B:

Search criteria: \[#[^1-4B]

“\[ - The literal character [ (must be escaped)

“# - The literal character # (not an operator, does not need to be escaped)

“[^” - Starts a character class, meaning any character but those described in the class

“1-4B - Range 1-4 (1, 2, 3, 4) and B

“]” - Ends the character class

 

Search sample and result:

Part [#9778C] - Found

Lot [#554] - Found

Part #977 - Not found (# not preceded by [)

Part [#155A] - Not found (# followed by 1)

 

Example 04:

Find a line that starts with "Detail," followed by one or more spaces, followed by one or more alphanumeric characters, and a Z:

Search criteria: ^Detail +[A-Z0-9]+Z

“^Detail” - Line must start with Detail

+” - (space character followed by +) One or more space characters

[A-Z0-9]+ - One or more ASCII alphanumeric characters

“Z - The literal character Z

 

Search sample and result:

Detail 143Z - Found

Detail AABZ - Found

Plot A Detail 3Z - Not Found (line does not start with Detail)

 

Example 05:

Find currency values in the form $#,###.## :

Search criteria: \$[0-9,]+\.[0-9][0-9]

\$ - Match must start with a dollar sign

[0-9,]+ - Matches one or more digits or commas

\. - Followed by a decimal point

[0-9][0-9] - Followed by exactly two digits

 

Search sample and result:

$12.34 - Found

$12,123.00 - Found

12,435.00 - Not found (does not start with $)

$12 - Not found (does not end with a decimal point and two digits)