Regular Expressions
Regular expressions provide a way to identify patterns of text in strings.
Bravura Security Fabric uses regular expressions to:
Match and block invalid passwords.
Identify users who it should not manage.
Extract text from Telnet/TN3270 screens in Telnet connector scripts.
Extract text from the output of password hashing programs in DBMS connector scripts.
Regular expressions use a shorthand of literal characters and special characters to define a pattern in a precise and compact way. Literal characters are case-sensitive. The regular expression parser used by Bravura Security Fabric uses the following special characters in literal strings:
Character | Purpose | Example | Match |
|---|---|---|---|
. | Matches any single character | a.c | aac , abc , a1c , a2c |
^ | Beginning of a line | ^hat | hat , hatch , not chat |
$ | End of a line | hat$ | hat , chat , not hatch |
| | Alternation | job | task | job or task |
( ) | Grouping | job(12 | 34) | job12 or job34 |
\ | Treat the following special character literally | \$5\.6\\7 | $5.6\7 |
The | alternates the longest possible string. That is, it matches job or task, and matches both jotask and jobask.
Grouping with ( ) limits the alternate branches.
Character sets
You can define a set of characters within a string. Character sets match any single character enclosed in square brackets [ ]. For example:
Expression | Match |
|---|---|
j[oa]n | jon or jan |
Use the - character between two characters in a set to indicate a range. A - character outside of a set, or at the beginning or end of a set, is treated literally. For example:
Expression | Match |
|---|---|
[a-c] | a , b , or c |
[1-3] | 1 , 2 , or 3 |
[ab-] | a , b , or - |
[B-D]-3 | B-3 , C-3 , or D-3 |
If the first character in the set is ^, then the character set matches any character that is not in the list. For example:
Expression | Match |
|---|---|
[^oa] | Any character except o and a |
All other special characters lose their meaning when included in a character set. For example:
Expression | Match |
|---|---|
^[^*\+.-] | Line must not start with *, \ , + , . ,or - |
To include a literal ] in the character set, make it the first character in the set. It can also be excluded by following ^. The ] character is also treated literally outside of a set. For example:
Expression | Match |
|---|---|
[^]a-] | Any character besides ] , a , and - |
[]a] | ] or a |
[a]] | a] |
Quantifiers
You can specify quantities of character sets, grouped characters, or individual characters. The quantifiers *, + , ? , and { } act on the preceding set, group, or individual character.
Character | Purpose | Example | Match |
|---|---|---|---|
* | Specifies 0 or more consecutive occurrences | ab*c | ac , abc , abbbbc |
+ | Specifies 1 or more consecutive occurrences | ab+c | abc , abbbbc |
? | Specifies 0 or 1 occurrence | colou?r (wo)?man | color or colour woman or man |
{ x } | Exactly <x> occurrences | ab { 4 } c | abbbbc |
{ x,y } | At least <x> , no more than <y> occurrences | ab { 2,4 } c | abbc , abbbc , abbbbc |
{ x, } | At least <x> occurrences | ab { 2, } c | abbc , abbbc |
{ ,x } | No more than <x> occurrences | ab { ,2 } c | ac , abc , or abbc |
Shorthand expressions
The following expressions are shorthand for longer or more complex regular expressions:
Expression | Purpose | Example | Match |
|---|---|---|---|
[:alpha:] | Matches must consist of letters. | [:alpha:]8,16 | aBcmGLeEhhi |
[:digit:] | Matches must consist of digits. [:digit:] is equivalent to [:d:] and \ d. | [[:digit:]]+ | 2962954576 |
[:upper:] | Matches must consist of uppercase characters. | [[:upper:][:digit:]]+ | 9DDD4MLAG13 |
[:alnum:] | Matches must be alphanumeric. [:alnum:] is short hand for [a-zA-Z0-9] in the ascii character set, but the use of [:alnum:] is preferred for compatibility with other languages and character sets. | [:alnum:]7[^[:digit:]] | a3dM9DD+ |
Examples
Only allow letters, numbers, exclamation point, and period | ^[a-zA-Z0-9!.]⋆$ |
At most 8 characters long | ^.,8$ |
Must start with a letter | ^[a-zA-Z] |
Must have a number | [0-9] |
Must end in -admin or -test | (-admin | -test)$ |
Must begin with three capital letters and an underscore | ^[A-Z] { 3 } _ |
See also
Bravura Security Fabric uses the ECMAScript regular expression grammar. For more information on regular expressions supported by Bravura Security Fabric, see:
The ECMA Script Language Specification at:
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
or
The Microsoft Developer Network (MSDN) TR1 Regular Expressions document at: