Game Development Reference
In-Depth Information
The most basic regular expression would be to match specific keywords, which
must be the same series of characters every time. In order to match this, the regex
is simply the series of characters with or without quotes:
Click here to view code image
// Matches new keyword
new
// Also matches new keyword
"new"
In a regular expression, there are also operators that have special meaning. The
[] operator means any character contained within the brackets will be matched.
This can also be combined with a hyphen to specify any character within a range.
Here's an example:
Click here to view code image
// Matches aac, abc, or acc
a[abc]c
// Matches aac, abc, acc, ..., azc
a[a-z]c
// You can combine multiple ranges...
// Matches above as well as aAc, ..., aZc
a[a-zA-Z]c
The + operator means “one or more of a particular character,” and the * operator
means “zero or more of a particular character.” These can be combined with the
[] operator to create expressions that can define most of the types of tokens in a
particular language:
Click here to view code image
// Matches one or more number (integer token)
[0-9]+
// Matches a single letter or underscore, followed
by zero or more
Search WWH ::




Custom Search