Sun Java Studio Creator 2 Update 1 – Online Help
 

About Regular Expressions

See Also

A regular expression is a way of specifying a search string based on common characteristics shared by each string in the set. Regular expressions can range from simple to complex, and the syntax is extensive. There are many different varieties of regular expressions, including grep, Perl, Tcl, Python, PHP, and awk. The IDE uses the Java package java.util.regex to perform the search. See java.util.regex.Pattern for a complete list of regular expression constructs that search a single line at at time in files. This topic presents some of the more common elements of the regular expressions used by the IDE.

Regular expressions use a number of special characters that specify a pattern to be matched. For example, the search string "java." matches "java" followed by a single character. This regular expression would match both "java." and "javax" in a source file.

The metacharacters supported by regular expressions are ([{\^$|)?*+. The following table shows how to use some of the metacharacters:

Expression Description
^ The beginning of a line
$ The end of a line
[abc]

a, b, or c

Example:
[rcb]at: matches rat, cat, bat, but not hat

[^abc] Any character except a, b, or c

Example:
[^rcb]at: matches hat, but not rat, cat, bat
The match is successful only if the first character of the input string does not contain any of the characters defined by the character class.

[a-zA-Z] a through z or A through Z, inclusive
[a-d[m-p]] a through d, or m through p: [a-dm-p]
[a-z&&[def]] d, e, or f
. Any character
\d A digit: [0-9]
\D A non-digit: [^0-9]
\s A white space character:
\S A non-white space character: [^\s]
\w A word character: [a-zA-Z_0-9]
\W A non-word character: [^\w]
Quantifiers enable you to specify the number of occurrences of whatever precedes it. You can use any character and any expression from the preceding table before the quantifier.
Quantifier Description
X? Match X once or not at all.
X* Match X zero or more times.
X+ Match X one or more times.
X{n} Match X exactly n times.
X{n,} Match X at least n times.
X{n,m} Match X at least n but not more than m times.

There are two ways to force a metacharacter to be treated as an ordinary character:

See Also
Project Tasks: Quick Reference
About the Projects and Files Windows
Finding Files or Items in a Project
 
 
 
Legal Notices. Copyright © 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Close