Regular Expressions


The Search...Find and Replace commands now support Regular Expressions.

Regular Expressions use special syntax to find text that matches specified pattern.

Search syntax:

a+        One or more occurrences of a

a*        Zero or more occurrences of a

a?        Zero or one (i.e. optional) occurrences of a

a{n}        Exactly n occurrences of a

a{n,}        n or more occurrences of a

a{,m}        Zero or at most m occurrences of a

a{n,m}        At least n but not more than m occurrences of a

a|b        Either a or b

a||b        a or b or both a and b in any order

abc        a followed by b followed by c

[abc]        A single character, one of a or b or c

[a-b]        A single character, ranging in value from a to b inclusive

[^abc]        A single character, any except a, b or c

(abc)        a followed by b followed by c

"abc"        The letters a followed by b followed by c with no special significance attached to a, b or c

.        Any character except a newline

^        Start of the line

$        End of the line

\a        The letter a, with no special significance attached to a, special forms:

\t        The tab character

\n        The newline character

\r        The return character

\f        The form feed character

\b        The backspace character

\xNN        The hex character NN

\ooo        The octal character ooo

\uNNNN        The hex Unicode character NNNN

\w        A single character, one of [a-zA-Z0-9_]

\W        Any single character not matching \w

\d        A single character [0-9]

\D        A single character not matching \d

\s        A whitespace character [\t\r\n\f\b\ ]

\S        A single character not matching \s

 

Search examples:

Expression        Matches        Does not match

"this"|"that"        this        This

 that        That

\d{2}\.\d{2}        23.45        2.4

 03.22        0.1

[a-zA-Z_]\w*        Identifier        2Identifiers

\(\*[\x01-\x7F]+\*\)        (* a comment *)        ( No comment *)

 

Replace:

Replace consists of search expressions and replace expression.

Search expression can have search groups that can be referred to in replace expressions.

Groups are marked by brackets (), there can be maximum of 9 groups and groups cannot be nested or overlapped.

Replace expression contains new text and can refer to groups of text from search expression using syntax %N where N is between 1 and 9.

 

Replace syntax:

%N        group N of found text

\t        The tab character

\n        The newline character

\r        The return character

\f        The form feed character

\b        The backspace character

\s        The space character

\xNN        The hex character NN

\ooo        The octal character ooo

\uNNNN        The hex Unicode character NNNN

 

Replace examples:

Search Expression:        ([^ ]+)(\ +)(was)(\ +)([^ ]+ere)

Replace Expression:        %1 is %5

Search Text:        bob    was here

Resulting Text:        bob is here

Search Text:        Jane was    there

Resulting Text:        Jane is there

 

Search Expression:        ("http://"|"mailto:"|"ftp://")([^ \n\r\"\<\\]+)

Replace Expression:        a=%1; b=%2

Search Text:        http://google.com.au

Resulting Text:        a=http://; b=google.com.au

Search Text:        ftp://microsoft.com

Resulting Text:        a=ftp://; b=microsoft.com

 



URL of this topic: www.copsmodels.com/webhelp/tabmate/hc_regex.htm

Link to full GEMPACK Manual

Link to GEMPACK homepage