判断字符串是数字、字符、还是...
2012-04-12 10:44
134 查看
int match(str pattern, str text)
match('<:D+>', s);判断字符串是否全部为数值
match('<:A+>', s);判断字符串是否全部为字符
match('<:N+>', s);判断字符串是否全部为数字或字符
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: Copy Code match("ab$cd","ab$cd"); //returns 0 match("ab\$cd","ab$cd"); //returns 0 - the backslash is not escaped match("ab\\$cd","ab$cd"); //returns 1 - the backslash and dollar sign are escaped |
< 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: 以什么打头的 Copy Code match("<abc","abcdef"); //returns 1 match("<abc","defabc"); //returns 0 match("^abc","abcdef"); //returns 1 match("^abc","defabc"); //returns 0 |
> | A 'greater than'(>) sign at the end of the expression is used to match the end of a line. For example: 以什么结尾 Copy Code match("abc>","abcdef"); //returns 0 match("abc>","defabc"); //returns 1 |
? or . | A question mark (?) or a full stop (.) will match any character. For example: Copy Code通配符 match("abc.def","abc#def"); //returns 1 match("colou?r","colouXr"); //returns 1 |
:a | Sets the match to letters. For example: 字母 Copy Code match("ab:acd","ab#cd"); //returns 0 match("ab:acd","abxyzcd"); //returns 0 match("ab:acd","abxcd"); //returns 1 |
:d | Sets the match to numeric characters. For example: 数字 Copy Code match("ab:dcd","ab3cd"); //returns 1 match("ab:dcd","ab123cd"); //returns 0 match("ab:dcd","abcd"); //returns 0 |
:n | Sets the match to alphanumeric characters. For example: 数字或字符 Copy Code match("ab:ncd","ab%cd"); //returns 0 match("ab:ncd","ab9cd"); //returns 1 match("ab:ncd","abXcd"); //returns 1 |
:SPACE | Where SPACE is the character ' '. Sets the match to blanks, tabulations, and control characters such as Enter (new line). For example: 空格,表格,控制符(回车) Copy Code match("ab: cd","ab cd"); //returns 1 match("ab: cd","ab\ncd"); //returns 1 match("ab: cd","ab\tcd"); //returns 1 match("ab: cd","ab cd"); //returns 0 - only the first space is matched |
* | An expression followed by an asterisk requires a match for none, one, or more occurrences of the preceding expression. For example: 全部由*前的字符串中的没有,一个,多个组成 Copy Code match("abc*d","abd"); //returns 1 match("abc*d","abcd"); //returns 1 match("abc*d","abcccd"); //returns 1 match("abc*d","abxd"); //returns 0 |
+ | An expression followed by a plus (+) sign requires a match for one or more occurrences of the preceding expression. For example: 全部由*前的字符串中的一个,多个组成 Copy Code match("abc+d","abd"); //returns 0 match("abc+d","abcd"); //returns 1 match("abc+d","abcccd"); //returns 1 match("abc+d","abxd"); //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: 全部由*前的字符串中的没有,一个组成 Copy Code match("colou-r","color"); //returns 1 match("colou-r","colour"); //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. 字符串范围 Copy Code match("[abc]","apple"); //returns 1 - matches the 'a' in apple match("[abc]","kiwi"); //returns 0 - kiwi does not contain an a, b, or c match("gr[ae]y","grey"); //returns 1 - also matches "gray" match("gr[ae]y","graey"); //returns 0 - only one character between "gr" and "y" is matched. |
[^] | If the first character in a text within square brackets is a circumflex (^), the expression matches all characters except those contained within the brackets. 不包括字符串范围 Copy Code match("[^bc]at","bat"); //returns 0 match("[^bc]at","hat"); //returns 1 match("[^abc]","bat"); //returns 1 - anything but a, b, or c is matched. The t is matched |
相关文章推荐
- Java判断字符串是字符或数字
- 【leetcode】对撞指针应用之回文字符串判断(忽略大小写,以及出数字外其他字符)
- C#判断字符串是否为数字字符串
- JS判断输入字符串长度(汉字算两个字符,字母数字算一个)
- C语言 判断一个字符是字母还是数字
- 判断字符串 中文字符 字母 数字 以及下划线
- 5.8.从键盘任意输入一个字符,编程判断该字符是数字字符、大写字母、小写字母、空格还是其他字符。
- JS判断输入字符串长度(汉字算两个字符,字母数字算一个)
- js判断输入字符串长度(汉字算两个字符,字母数字算一个)
- 过滤字符串 判断字符 数字判断
- @V@ java代码笔记2010-06-12:java控制台输入各类型类实现;以及判断输入字符串里面是否有数字的两种方法:方法1:转换成字符数组;方法2:正则表达式。
- 输入一个字符判断该字符为数字,大写字母,小写字母,还是其他字符
- 判断一个字符串中数字,字符,空格和其他字符的个数
- 判断用户输入的是数字还是字符
- iOS中 判断字符串 中文字符 字母 数字 以及下划线
- C#判断输入的字符串中是否含有大写字母,小写字母,数字,字符
- python 中输入一个字符串,判断这个字符串中有多少个字符、数字、空格、特殊字符
- js判断输入字符串长度(汉字算两个字符,字母数字算一个)
- 从键盘输入一个字符,判断其是字母字符,还是数字字符,还是其他字符
- 判断字符还是数字的方法。