Previous: , Up: List Operators ([] and [^])   [Contents][Index]


18.3.6.4 The Range Operator (-)

Regex recognizes range expressions inside a list. They represent those characters that fall between two elements in the current collating sequence. You form a range expression by putting a range operator between two of any of the following: characters, collating elements, collating symbols, and equivalence class expressions. The starting point of the range and the ending point of the range don’t have to be the same kind of item, e.g., the starting point could be a collating element and the ending point could be an equivalence class expression. If a range’s ending point is an equivalence class, then all the collating elements in that class will be in the range.5-’ represents the range operator. For example, ‘a-f’ within a list represents all the characters from ‘a’ through ‘f’ inclusively.

If the syntax bit RE_NO_EMPTY_RANGES is set, then if the range’s ending point collates less than its starting point, the range (and the regular expression containing it) is invalid. For example, the regular expression ‘[z-a]’ would be invalid. If this bit isn’t set, then Regex considers such a range to be empty.

Since ‘-’ represents the range operator, if you want to make a ‘-’ character itself a list item, you must do one of the following:

For example, ‘[-a-z]’ matches a lowercase letter or a hyphen (in English, in ASCII).


Footnotes

(5)

You can’t use a character class for the starting or ending point of a range, since a character class is not a single character.


Previous: Character Class Operators ([::]), Up: List Operators ([] and [^])   [Contents][Index]