• 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:

    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 cd");  //returns 1
        match("ab: cd","ab cd");  //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

  • 相关阅读:
    ARM裸板开发:04_MMU 链接地址与运行地址不一致时,(SDRAM)初始化程序地址无关码问题的分析
    Win7 环境下虚拟机内 Samba 服务器的安装、配置以及与主机的通信实现
    J-Link固件烧录以及使用J-Flash向arm硬件板下载固件程序
    九种排序算法分析与实现
    Window下通过CuteFTP与Linux虚拟机连接失败的原因总结及解决方法
    Linux常见目录及命令介绍
    虚拟机访问互联网的方法 -- 以RedHat系为例
    简单计算器的实现
    组合
    python的类的继承-接口继承-归一化设计
  • 原文地址:https://www.cnblogs.com/KobeZhang/p/4739691.html
Copyright © 2020-2023  润新知