Resin 1.1
FAQ
Reference
JavaDoc
Demo
Java Tutorial
Getting Started
Configuration
Servlet
JSP
XTP/XSL
JavaScript
JS Library
Source Text
Literals
Regexp
Operators
Objects
Functions
Statements
Java Wrapping
Regular Expressions
Resin's regular expressions are based on Perl5 but matche 16-bit strings. The JavaScript interface is based on Netscape 1.3. See string objects and regular expression objects for API details.
/regexp/[i][g][m][x]
The regexp syntax follows Perl5. Characters escape the same as for strings.
Regexp Literals
character | Match character.
[set] | Matches any characters in set.
[^set] | Matches any characters not in set.
. | Matches any character except newline, i.e. [^\n]
\s | Matches whitespace, i.e. [ \t\r\n\v\f]
\S | Matches non-whitespace, i.e. [^ \t\r\n\v\f]
\d | Matches any digit, i.e. [0-9]
\D | Matches any non-digit, i.e. [^0-9]
\w | Matches any alphanumeric character, i.e. [a-zA-Z0-9_]
\W | Matches any non-alphanumeric character, i.e. [^a-zA-Z0-9_]
ab | Match a followed by b.
(a) | Matches if a matches, storing the submatch.
\n | Matches the nth submatch.
(?:a) | Match a. Does not store the submatch.
a|b | Match if a matches or if b matches.
a* | Match as many a as possible.
a+ | Match as many a as possible but at least one.
a? | Try to match a, otherwise just match.
a{m,n} | Try to match at most n repetitions of a, but match at least m of them.
a{n} | Match exactly n repetitions of a.
a*? | Match as few a as possible.
a+? | Match as few a as possible but at least one.
a?? | Try to match without a, otherwise try to match a.
^ | Matches at the beginning of the line.
$ | Matches at the end of the line.
\b | Matches at a word boundary.
\B | Matches if not at a word boundary.
\A | Matches at the beginning of the string.
\Z | Matches at the end of the string.
\G | Matches at the beginning of the test (for a /g).
(?=a) | Matches only if a follows but do not match a as part of the matched string.
(?!a) | Matches only if a does not follow.
(?#text) | Match always. text is just a comment.
(?imsx) | Sets the given flag for the entire regular expression.
Regexp Literals
### character
Match character.
"cab".search(/a/)
| 1

### [set]

Matches any characters in set.

Sets
Pattern | Name | Meaning
--- | --- | ---
x | Character match | Match a
x-y | Range match | Match any character from x to y
x y | Union | Match any character in x or y
\s | Space match | Matches [ \t\r\n\v\f]
\S | Non-space match | Matches [^ \t\r\n\v\f]
\d | Digit match | Matches [0-9]
\D | Non-digit match | Matches [^0-9]
\w | Alphanumeric match | Matches [a-zA-Z0-9_]
\W | Non-alphanumeric match | Matches [^a-zA-Z0-9_]

"cab".replace(/[ab]/g, '*')
| c**
"bark".replace(/[a-c]/g, '*')
| **rk

### [^set]

Matches any characters not in set.

"cab".replace(/[^ab]/g, '*')
| *ab
"bark".replace(/[^a-c]/g, '*')
| ba**

### .

Matches any character except newline, i.e. [^\n]

"a yellow cab".search(/c.b/)
| 9

### \s

Matches whitespace, i.e. [ \t\r\n\v\f]

"c a\tb\n".replace(/\s/, ':')
| c:a:b:

### \S

Matches non-whitespace, i.e. [^ \t\r\n\v\f]

### \d

Matches any digit, i.e. [0-9]

"buying 500".search(/\d+/)
| 7

### \D

Matches any non-digit, i.e. [^0-9]

### \w

Matches any alphanumeric character, i.e. [a-zA-Z0-9_]

### \W

Matches any non-alphanumeric character, i.e. [^a-zA-Z0-9_]

### ab

Match a followed by b.

"a big car".search(/.ar/)
| 6

### (a)

Matches if a matches, storing the submatch.

"repeat a repeat".match(/(.+).* \1/)

["at a", "a"]

### \n

Matches the nth submatch.

### (?:a)

Match a. Does not store the submatch.

"big".match(/b(?:i|a)g/)
| ["big"]
"bag".match(/b(?:i|a)g/)
| ["bag"]
"big".match(/b(i|a)g/)
| ["big", "i"]

### a|b

Match if a matches or if b matches.

### a*

Match as many a as possible.

### a+

Match as many a as possible but at least one.

### a?

Try to match a, otherwise just match.

### a{m,n}

Try to match at most n repetitions of a, but match at least m of them. If m is omitted, it is treated as 0. If n is omitted, it is treated as infinity.

### a{n}

Match exactly n repetitions of a.

### a*?

Match as few a as possible.

"big bug".match(/b.*?g/)
| ["big"]
"big bug".match(/b.*g/)
| ["big bug"]

### a+?

Match as few a as possible but at least one.

### a??

Try to match without a, otherwise try to match a.

### ^

Matches at the beginning of the line.

### $

Matches at the end of the line.

### \b

Matches at a word boundary.

"a big red cab".replace(/\b/g, ":");
:a: :big: :red: :cab

### \B

Matches if not at a word boundary.

### \A

Matches at the beginning of the string.

### \Z

Matches at the end of the string.

### \G

Matches at the beginning of the test (for a /g).

### (?=a)

Matches only if a follows but do not match a as part of the matched string.

"500 at 57%".match(/\d+(?=%)/)
| ["57"]
"500 at 57%".match(/\d+/)
| ["500"]

### (?!a)

Matches only if a does not follow.

"57% off 500".match(/\d+(?!%|\d)/)
| ["500"]
"57% off 500".match(/\d+/)
| ["57"]

### (?#text)

Match always. text is just a comment.

### (?imsx)

Sets the given flag for the entire regular expression.

Literals |  | Operators

Copyright © 1998-2000 Caucho Technology. All rights reserved.
Last modified: Thu, 16 Sep 1999 14:56:48 -0700 (PDT)