35 coaches online • Server time: 11:39
* * * Did you know? The most deaths in a single match is 8.
Log in
Recent Forum Topics goto Post GRUDGE FEST: OSBBL D...goto Post New Metagame: Rotter...goto Post Majors Finals Replay...

Regular expressions are a very powerful way of filtering strings.

The "normal" way of describing these are provided below. I have added examples to make it easier to understand:

A regular expression is one or more branches separated by `|´, matching anything that matches any of the branches.

Example 1:
foo|bar
This matches anything that contains the strings `foo´ or `bar´ such as: afoot, barred, barefoot.

A branch is zero or more constraints or quantified atoms, concatenated. It matches a match for the first, followed by a match for the second, etc; an empty branch matches the empty string.

A quantified atom is an atom possibly followed by a single quatifier. Without a quantifier, it matches a match for the atom. The quantifiers, and what a so-quantified atom matches, are:

* - A sequenve of 0 or more matches of the atom
+ - A sequence of 1 or more matches of the atom
? - A sequence of 0 or 1 matches of the atom
{m} - A sequence of exactly m matches of the atom
[m,} - A sequence of m or more matches of the atom
{m,n} - A sequence of m through n (inclusive) matches of the atom; m may not exceed n
*? +? ?? {m}? {m,}? {m,n}? - non-greedy quantifiers, which match the same possibilities, but prefer the smallest number rather than the largest number of matches

An atom is one of:

(re) - (where re is any regular expression) matches a match for re, with the match noted for possible reporting. (Note that bowlbot doesn't use this "reporting" facility so this is only useful for quantifying).
(?:re) - as previous, but does no reporting (so for bowlbot, this is useless)
() - matches an empty string
[chars] - a bracket expression, matching any one of the chars.
. - (full stop) matches any single character
{ - when followed by a character other than a digit, matches the left-brace character `{´; when followed by a digit, it is the beginning of a bound (see above)
x - where x is a single character with no other significance, matches that character.

A constraint matches an empty string when specific conditions are met. A constraint may not be followed by a quantifier. The simple constraints are as follows.

^ - matches at the beginning of a line (for bowlbot, each team name is considered a separate line)
$ - matches at the end of a line

A regular expression may not end with `\´.

Example 2:
^foo
Matches any string that begins with the string foo: foot

Example 3:
fo+
Matches any string that contains an f followed by any number of `o´s: surface, afoot

Example 4:
[bar]{2,}$
Matches any string which ends with the last two characters being b, a or r: bar, dab, car, abracadabra

Last update: August 21, 2003