Introduction to Regular Expressions PHP regular expression special characters [:alnum:] [:alpha:] etc.
For example, ‘<font style="color:rgb(0, 0, 0);">[[:alnum:]]</font>’ means ‘<font style="color:rgb(0, 0, 0);">[0-9A-Za-z]</font>’, Two very important special characters in regular expressions are "[ ]". They can match characters that appear inside "[]"; for example, "/[az]/" can match the single character "a" or "z"; if you change the above expression to "/[a-z]/", it can match any single lowercase letter, such as "a", "b", and so on. If a "^" appears inside "[]", it means the expression does NOT match the characters listed inside "[]"; for example, "/[^a-z]/" does not match any lowercase letter! In addition, regular expressions provide several default character classes for "[]", as follows: # '[:alnum:]' matches any letter Alphanumeric characters: '[:alpha:]' and '[:digit:]'. # '[:alpha:]' matches any letter or digit Alphabetic characters: '[:lower:]' and '[:upper:]'. # '[:blank:]' Blank characters: space and tab. # '[:cntrl:]' Control characters. In ASCII, these characters have octal codes 000 through 037, and 177 ('DEL'). In other character sets, these are the equivalent characters, if any. # '[:digit:]' matches any digit Digits: '0 1 2 3 4 5 6 7 8 9'. # '[:graph:]' Graphical characters: '[:alnum:]' and '[:punct:]'. # '[:lower:]' matches any lowercase letter Lower-case letters: 'a b c d e f g h i j k l m n o p q r s t u v w x y z'. # '[:print:]' Printable characters: '[:alnum:]', '[:punct:]', and space. # '[:punct:]' matches any punctuation character Punctuation characters: '! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ' { | } ~'. # '[:space:]' matches whitespace characters Space characters: tab, newline, vertical tab, form feed, carriage return, and space. # '[:upper:]' matches any uppercase letter Upper-case letters: 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'. # '[:xdigit:]' matches any hexadecimal digit Hexadecimal digits: '0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f'. Background First, let’s look at a piece of regex that is very common in WAFs,
...