In character sets within regular expressions, you can include a character class. You enclose the character class inside square brackets, as the following example shows:
REReplace ("Adobe Web Site","[[:space:]]","*","ALL")
This code replaces all the spaces with *, producing this string:
Adobe*Web*Site
You can combine character classes with other expressions within a character set. For example, the regular expression [[:space:]123] searches for a space, 1, 2, or 3. The following example also uses a character class in a regular expression:
<cfset IndexOfOccurrence=REFind("[[:space:]][A-Z]+[[:space:]]", "Some BIG string")> <!--- The value of IndexOfOccurrence is 5 --->
The following table shows the character classes that ColdFusion supports. Regular expressions using these classes match any Unicode character in the class, not just ASCII or ISO-8859 characters.
Character class |
Matches |
---|---|
:alpha: |
Any alphabetic character. |
:upper: |
Any uppercase alphabetic character. |
:lower: |
Any lowercase alphabetic character |
:digit: |
Any digit. Same as \d. |
:alnum: |
Any alphanumeric character. Same as \w. |
:xdigit: |
Any hexadecimal digit. Same as [0-9A-Fa-f]. |
:blank: |
Space or a tab. |
:space: |
Any whitespace character. Same as \s. |
:print: |
Any alphanumeric, punctuation, or space character. |
:punct: |
Any punctuation character |
:graph: |
Any alphanumeric or punctuation character. |
:cntrl: |
Any character not part of the character classes [:upper:], [:lower:], [:alpha:], [:digit:], [:punct:], [:graph:], [:print:], or [:xdigit:]. |
:word: |
Any alphanumeric character, plus the underscore (_) |
:ascii: |
The ASCII characters, in the Hexadecimal range 0 - 7F |