Regular Expressions in Q1
Q1 allows the use of regular expressions in most of the places where
a string comparison is required (for example when searching a list item
by name or a window by its title). You can specify you want to use a
regular expression match by prefixing the pattern with the backslash
character (\). Note that the syntax of some script languages
(for example JScript) allows backslash characters in strings only if they
are escaped by a second backslash ("\\" = "\").
var item1 = listbox.findItem("a*b");
var item2 = listbox.findItem("\\a*b");
Syntax
Regular expressions allow a great deal of flexibility when working with
strings, but it may take some time to get used to their syntax, that is
if they are not already familiar to you.
A regular expression pattern describes how a string should look
in order to be considered a valid match. It is composed of string
literals (letters and numbers) together with escape characters which
define matching rules:
- '.' (dot character) matches any single character.
- '*' placed after an expression matches the expression repeated
zero or more times. For example 'ba*' will match 'b', 'ba', 'baa' and
so on. The pattern '.*' will match any number of any characters.
- '+' behaves like '*' but the expression has to appear at
least once.
- '?' allows an expression to appear zero or one times.
- '{min,max}' allows an expression to be repeated at least
min times but no more than max times. For example
'a{1,3}' matches 'a', 'aa' and 'aaa', 'a{2,}' matches the character
'a' repeated at least two times and 'a{2}' matches 'aa'.
- '()' treats the expression within parenthesis as a group
and all modifiers apply to the whole group. For example '(abc)*' will
match 'abc', 'abcabc' and so on.
- '|' matches either the expression on the left of | or
the one on the right. For example 'abc|xyz' matches either 'abc'
or 'xyz'.
- '[]' matches a character belonging to the set specified
within the sqare brackets. Sets can be defined as follows:
- [abc] will match one character which can be either 'a', 'b' or 'c'.
- [a-z] will match one character between 'a' and 'z'.
- [^abcX-Z] will match any one character which is not 'a', 'b', 'c', 'X', 'Y' or 'Z'.
- '^' matches the beginning of a line.
- '$' matches the end of a line.
- '\<' matches the beginning of a word.
- '\>' matches the end of a word.
- '\x{code}' allows to specify a character by its
hexadecimal code.
- '[[:class:]]' allows to specify a character by its
class. Available classes are:
- [[:alnum:]] Alphanumeric characters.
- [[:alpha:]] Alphabetical character (a-z and A-Z).
- [[:blank:]] Blank character (spaces or tabs).
- [[:digit:]] Digits (0-9).
- [[:lower:]] Lower case characters (a-z).
- [[:punct:]] Punctuation characters.
- [[:space:]] Whitespace characters.
- [[:upper:]] Upper case characters (A-Z).
- [[:xdigit:]] Hexadecimal digit characters (0-9, a-f and A-F).
- [[:word:]] Word characters (alphanumeric characters plus '_').
- [[:unicode:]] Character whose code is greater than 255.
 
© 2003 Lightweight Technologies. All rights reserved.
© 1998-2001 Dr John Maddock.
Regular expression support and documentation is provided under the following terms: "Permission to use, copy,
modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and that both that copyright notice and this
permission notice appear in supporting documentation. Dr John Maddock makes no representations about the
suitability of this software for any purpose. It is provided "as is" without express or implied warranty."