Table of Contents

Search Patterns

NOTE: As of the latest dev version of PN, the regular expressions engine is being replaced and this section is likely to change.

Regular Expressions allow complicated and flexible search/replace using a specific syntax.

Note: Multi-line expressions (involving \n, \r, etc) are not yet supported. See Restrictions.

Pattern Meaning
.
Matches any character
\(
This marks the start of a region for tagging a match.
\)
This marks the end of a tagged region.
\1, \2, etc
This refers to the first through ninth (\1 to \9) tagged region when replacing. For example, if the search string was Fred\([1-9]\)XXX and the replace string was Sam\1YYY, when applied to Fred2XXX this would generate Sam2YYY.
\<
This matches the start of a word using Scintilla's definitions of words.
\>
This matches the end of a word using Scintilla's definition of words.
\x
This allows you to use a character x that would otherwise have a special meaning. For example, \[ would be interpreted as [ and not as the start of a character set.
[...]
This indicates a set of characters, for example, [abc] means any of the characters a, b or c. You can also use ranges, for example [a-z] for any lower case character.
[^...]
The complement of the characters in the set. For example,
[^A-Za-z]

means any character except an alphabetic character.

^
This matches the start of a line (unless used inside a set, see above).
$
This matches the end of a line.
*
This matches 0 or more times. For example, Sa*m matches Sm, Sam, Saam, Saaam and so on.
+
This matches 1 or more times. For example, Sa+m matches Sam, Saam, Saaam and so on.

Replacing

Regular Expressions supports tagged expressions. This is accomplished using \( and \) to surround the text you want tagged, and then using \1 in the replace string to substitute the first matched text, \2 for the second, etc.

For example:

Text body Search string Replace string Result
Hi my name is Fred my name is \(.+\) my name is not \1 Hi my name is not Fred
The quick brown fox jumped over the fat lazy dog brown \(.+\) jumped over the \(.+\) brown \2 jumped over the \1 The quick brown fat jumped over the fox lazy dog

Restrictions

Support for regular expressions in PN2 is currently limited, the supported patterns and syntax are a very small subset of the powerful expressions supported by perl. The biggest restriction is that regular expressions match only within a single line, you cannot use multi-line regular expressions. As a workaround to the lack of multi-line search, you can instead use BackslashExpressions.

There are plans to improve this support by using the PCRE library (used elsewhere in PN2) to provide document searching. If you're interested in helping please make yourself known to the pn-discuss mailing list: PN Mailing Lists.

Other Significant Differences from PCREs

* Unescaped parentheses match themselves. For grouping, use \( and \).

Examples

Description Search Replace
Remove leading whitespace on each line ^[ \t]*
Change getVariable() to setVariable() get\([A-Za-z0-9_]+\)() set\1()

See Also

* Backslash Expressions - very limited search/replace syntax, but supports multi-line searches.