match
int match(str pattern, str text)
match('<:D+>', s);判断字符串是否全部为数值
match('<:A+>', s);判断字符串是否全部为字符
match('<:N+>', s);判断字符串是否全部为数字或字符
Character |
Description |
\ |
A backslash causes a specific character to be matched. Remember to escape backslashes. For example: match("ab$cd","ab$cd"); //returns 0 |
< or ^ |
A 'less than'(<) sign or a circumflex (^) at the start of an expression is used to match the start of a line. For example: 以什么打头的 match("<abc","abcdef"); //returns 1 |
> |
A 'greater than'(>) sign at the end of the expression is used to match the end of a line. For example: 以什么结尾 match("abc>","abcdef"); //returns 0 |
? or . |
A question mark (?) or a full stop (.) will match any character. For example: Copy Code通配符 match("abc.def","abc#def"); //returns 1 |
:a |
Sets the match to letters. For example: 字母 match("ab:acd","ab#cd"); //returns 0 |
:d |
Sets the match to numeric characters. For example: 数字 match("ab:dcd","ab3cd"); //returns 1 |
:n |
Sets the match to alphanumeric characters. For example: 数字或字符 match("ab:ncd","ab%cd"); //returns 0 |
:SPACE |
Where SPACE is the character ' '. Sets the match to blanks, tabulations, and control characters such as Enter (new line). For example: 空格,表格,控制符(回车) match("ab: cd","ab cd"); //returns 1 |
* |
An expression followed by an asterisk requires a match for none, one, or more occurrences of the preceding expression. For example: 全部由*前的字符串中的没有,一个,多个组成 match("abc*d","abd"); //returns 1 |
+ |
An expression followed by a plus (+) sign requires a match for one or more occurrences of the preceding expression. For example: 全部由*前的字符串中的一个,多个组成 match("abc+d","abd"); //returns 0 |
- |
An expression followed by a minus (-) sign requires a match for one or no occurrences of the preceding expression. Basically, the preceding expression is optional. For example: 全部由*前的字符串中的没有,一个组成 match("colou-r","color"); //returns 1 |
[] |
Matches a single character with any character contained within the brackets.A range of characters can be specified by two characters separated by '-' (minus). For example, "[a-z]" matches all letters between a and z, [0-9] matches a digit, [0-9a-f] matches a hexadecimal digit. 字符串范围 match("[abc]","apple"); //returns 1 - matches the 'a' in apple |
[^] |
If the first character in a text within square brackets is a circumflex (^), the expression matches all characters except those contained within the brackets. 不包括字符串范围 match("[^bc]at","bat"); //returns 0 |
posted on 2015-08-18 16:08 Kobe.Zhang 阅读(166) 评论(0) 编辑 收藏 举报