Pattern Library
The pattern library defines regular expressions and string display formats that
can be used by all systems. Each regular expression or display format has a key
that can be referenced in the system configuration files. The key and their accociated
patterns are defined in the PatternLibrary.xml file in the TurnObjects config folder.
Display Formats
Display formats help to format the object data in a specified way. The DisplayFormatId of the schema property is used to specify how the value will be displayed. A good example of using a display format is to apply one to a date. A formater like {0:d} will fomat the date to a short form (MM/DD/YYYY). The following tables show how to use display formatting to represent data.
Dates
|
d |
Short date |
03/25/1975 |
|
D |
Long date |
March 25, 1975 |
|
t |
Short time |
11:58 PM |
|
T |
Long time |
23:58:00 PM |
|
f |
Full date & time
|
March 25, 1975 23:58 PM |
|
F |
Full date & time (long) |
March 25, 1975 23:58:00 PM |
|
g |
Default date & time |
03/25/1975 11:58 PM |
|
G |
Default date & time (long) |
03/25/1975 11:58:00 PM |
|
M |
Month day pattern |
March 25 |
|
r |
RFC1123 date string |
Tue, 25 mar 1975 23:58:00 GMT |
|
s |
Sortable date string |
1975-03-25T23:58:00 |
|
u |
Universal sortable, local time |
1975-03-25 23:58:00Z |
|
U |
Universal sortable, GMT |
March 25, 1975 23:58:00 AM |
|
Y |
Year month pattern |
March, 1975 |
Date Formatting
|
dd |
Day |
{0:dd} |
25 |
|
ddd |
Day name |
{0:ddd} |
Mon |
|
dddd |
Full day name |
{0:dddd} |
Monday |
|
f, ff, … |
Second fractions |
{0:fff} |
432 |
|
gg, … |
Era |
{0:gg} |
A.D. |
|
hh |
2 digit hour |
{0:hh} |
12 |
|
HH |
2 digit hour, 24hr format |
{0:HH} |
24 |
|
mm |
Minute 00-59 |
{0:mm} |
58 |
|
MM |
Month 01-12 |
{0:MM} |
3 |
|
MMM |
Month abbreviation |
{0:MMM} |
Mar |
|
MMMM |
Full month name |
{0:MMMM} |
march |
|
ss |
Seconds 00-59 |
{0:ss} |
33 |
|
tt |
AM or PM |
{0:tt} |
PM |
|
yy |
Year, 2 digits |
{0:yy} |
07 |
|
yyyy |
Year |
{0:yyyy} |
2007 |
|
zz |
Timezone offset, 2 digits |
{0:zz} |
-06 |
|
zzz |
Full timezone offset |
{0:zzz} |
-06:00 |
|
: |
Separator |
{0:hh:mm:ss} |
11:58:00 |
|
/ |
Separator |
{0:dd/MM/yyyy} |
03/25/1975 |
Numbers
| c |
Currency |
{0:c} |
$1.33 |
-$13,200 |
|
d |
Decimal (Whole number) |
{0:d} |
System.FormatException |
-13200 |
|
e |
Scientific |
{0:e} |
1.330000e+000 |
-1.320000e+004 |
|
f |
Fixed point |
{0:f} |
1.33 |
-13200.00 |
|
g |
General |
{0:g} |
1.33 |
-13200 |
|
n |
Number with commas for thousands |
{0:n} |
1.33 |
-13,200 |
|
r |
Round trippable |
{0:r} |
1.33 |
System.FormatException |
|
x |
Hexadecimal |
{0:x4} |
System.FormatException |
3390 |
Number Formatting
|
0 |
Zero placeholder |
{0:00.0000} |
1700.3300 |
Pads with zeroes. |
|
# |
Digit placeholder |
{0:(#).##} |
(1700).33 |
|
|
. |
Decimal point |
{0:0.0} |
1700.3 |
|
|
, |
Thousand separator |
{0:0,0} |
1,700 |
Must be between two zeroes. |
|
,. |
Number scaling |
{0:0,.}
|
2 |
Comma adjacent to Period scales by 1000. |
|
% |
Percent |
{0:0%} |
170033% |
Multiplies by 100, adds % sign. |
|
e |
Exponent placeholder |
{0:00e+0} |
17e+2 |
Many exponent formats available. |
|
; |
Group separator |
see below |
|
Enumerators
|
g |
Default (Flag names if available, otherwise decimal) |
|
f |
Flags always |
|
d |
Integer always |
|
x |
Eight digit hex. |
Regular Expressions
A regular expression is a string that describes or matches a set of strings. The
TurnObjects system uses regular expressions to validate user input by ensuring it
matches a desired format. The InputRegExId for each property can be used to identify
the regular expression in the pattern library that will be used to validate the
input. A common use for a regular expression is to match up strings that should
represent email addresses. A basic regular expression for email would look like
the following:
\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
Metacharacters
A character class is a set of characters that will find a match if any one of the
characters included in the set matches.
|
^ |
Start of a string. |
|
$ |
End of a string. |
|
. |
Any character (except \n newline) |
|
| |
Alternation. |
|
{...} |
Explicit quantifier notation. |
|
[...] |
Explicit set of characters to match. |
|
(...) |
Logical grouping of part of an expression. |
|
* |
0 or more of previous expression. |
|
+ |
1 or more of previous expression. |
|
? |
0 or 1 of previous expression; also forces minimal matching when an expression might
match several strings within a search string. |
|
\ |
Preceding one of the above, it makes it a literal instead of a special character.
Preceding a special matching character, see below. |
Character Class
|
|
Matches any character except \n. If modified by the Singleline option, a period
character matches any character. |
|
[abc] |
Matches any single character included in the specified set of characters. |
|
[^abc] |
Matches any single character not in the specified set of characters. |
| [0-9a-fA-F] |
Use of a hyphen (–) allows specification of contiguous character ranges. |
|
\p{name} |
Matches any character in the named character class specified by {name}. |
|
\P{name} |
Matches text not included in groups and block ranges specified in {name}. |
| \w |
Matches any word character. |
| \W |
Matches any nonword character. |
| \s |
Matches any white-space character. |
| \S |
Matches any non-white-space character. |
| \d |
Matches any decimal digit. |
| \D |
Matches any nondigit. |
Articles found by doing a web search on regular expression or regex will provided
a better understanging and many examples of using regular expressions.
© 2008 TurnObjects All rights reserved. Legal | Privacy
|