Character classes?are a new feature introduced in the?POSIX?standard. A character class is a special notation for describing lists of characters that have a specific attribute,but where the actual characters themselves can vary from country to country and/or from character set to character set. For example,the notion of what is an alphabetic character differs in the USA and in France.
A character class is only valid in a regular expression?inside?the brackets of a character list. Character classes consist of?[:,a keyword denoting the class,and?:]. The character classes defined by the?POSIX?standard are:
|
</tr>
<tr valign="top">
<td>[:alpha:]</td>
<td valign="bottom">Alphabetic characters.</td></tr>
<tr valign="top">
<td>[:blank:]</td>
<td valign="bottom">Space or tab characters.</td>
</tr>
<tr valign="top">
<td>[:cntrl:]</td>
<td valign="bottom">Control characters.</td>
</tr>
<tr valign="top">
<td>[:digit:]</td>
<td valign="bottom">Numeric characters.</td>
</tr>
<tr valign="top">
<td>[:graph:]</td>
<td valign="bottom">Characters that are both printable and visible. (A space is printable,but not visible,while an?a?is both.)</td>
</tr>
<tr valign="top">
<td>[:lower:]</td>
<td valign="bottom">Lower-case alphabetic characters.</td>
</tr>
<tr valign="top">
<td>[:print:]</td>
<td valign="bottom">Printable characters (characters that are not control characters.)</td>
</tr>
<tr valign="top">
<td>[:punct:]</td>
<td valign="bottom">Punctuation characters (characters that are not letter,digits,control characters,or space characters).</td>
</tr>
<tr valign="top">
<td>[:space:]</td>
<td valign="bottom">Space characters (such as space,tab,and formfeed,to name a few).</td>
</tr>
<tr valign="top">
<td>[:upper:]</td>
<td valign="bottom">Upper-case alphabetic characters.</td>
</tr>
<tr valign="top">
<td colspan="2">[:xdigit:]</td>
</tr>
<tr valign="top">
<td width="8%">?</td>
<td>Characters that are hexadecimal digits.</td>
</tr>
(编辑:源码网)【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!