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\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

时间: 2024-10-27 19:36:44

match的相关文章

maven -- 问题解决(三)Java compiler level does not match the version of the installed Java project facet

问题: Java compiler level does not match the version of the installed Java project facet 解决方法如下: properties->Java Compiler,修改JDK版本,然后Apply

-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match.chan

第一次使用Maven ,在eclipse中执行pom.xml文件的时候报错. -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match. 参考网上的解决方案: 设一个环境变量M2_HOME指向你的maven安装目录 M2_HOME=D:\Apps\apache-maven-3.3.1 然后在Window->Prefe

HDU3081Marriage Match II(二分答案+并查集+最大流SAP)经典

Marriage Match II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2507    Accepted Submission(s): 856 Problem Description Presumably, you all have known the question of stable marriage match. A

eBay搜索排名规则Best Match

对于电商卖家而言,站内搜索时最重要的流量来源,因此作为卖家必须要了解平台的搜索排名规则,只有店铺的操作符合搜索排名规则,才能有效地提升商品的搜索曝光率.对于eBay卖家而言最重要搜索排名规则就是"最佳配/BestMatch".今天就带大家了解什么是ebay Best Match? 什么是Best Match? 第一,Best Match来源: 为了提高买家用户体验,卖家需要迎合买家需求和习惯. 第二,买家和卖家的匹配: 通过搜索排名规则,引导卖家不断提高买家的购物体验.Best Mat

Python学习笔记——基础篇【第五周】——re.match与re.search的区别

正则表达式 语法: import re #导入模块名 p = re.compile("^[0-9]") #生成要匹配的正则对象 , ^代表从开头匹配,[0-9]代表匹配0至9的任意一个数字, 所以这里的意思是对传进来的字符串进行匹配,如果这个字符串的开头第一个字符是数字,就代表匹配上了 m = p.match('14534Abc') #按上面生成的正则对象 去匹配 字符串, 如果能匹配成功,这个m就会有值, 否则m为None if m: #不为空代表匹配上了 print(m.group

5.Python里面match()和search()的区别?

Python里面match()和search()的区别? '''match()从第一个字符开始找,如果第一个就不匹配,会直接返回None,不继续匹配.主要用于匹配开头''' #coding=utf-8 import re result = re.match("www","www.cn") result.group() >>'www' # 否则返回None '''search()会在整个字符串中查找,知道找到一个匹配的''' #coding=utf-8 i

Mybatis mapper must match错误

Mybatis mapper must match ((cache-ref|cache|resultMap*|parameterMap*|sql*|insert*|update*|delete*|select*) 出现此问题是由于自己的xml内的mybatis标签未按照指定的顺序来编写. 顺序如下: cache-ref cache resultMap* parameterMap* sql* insert* update* delete* select

js正则表达式的match test exec replace函数

js正则表达式的方法:一种正则在前,一种正则在后: 使用: 1.exec var res = /\-[a-z]/g .exec("font-size"); console.log(res); 得到的结果: 所以返回的是一个数组,第一个为匹配值,第二个是匹配的位置,第三个是输入的数 2.test var res = /\-[a-z]/g .test("font-size");console.log(res); 返回为一个布尔值 3.match var res =(&q

awk之match函数

格式:match(string,regexp,array)    和string~regexp的作用类似 说明:不依靠$1,2,3...来提取特定的列. 没有array的情况下:通过regexp,在string中寻找最左边,最长的substring,返回substring的index位置. 有array的情况下:在regexp中用()将要组成的array的内容按顺序弄好,a[1]代表第一个()的内容,a[2]代表第二个()的内容,以此类推. echo "gene_type "mrna&

Rust 1.7.0 匹配器 match 的简介和使用

使用过正則表達式的人应该都知道 matcher ,通过 matcher 匹配器运算正則表達式,完毕一系列的匹配规则. 在Rust 中 没有 switch 语句.matcher 就是 switch 的一个变形,但比其它语言中的 switch 更强大! 一.简单举例说明 简单的 matcher 和 if 语句很相似,假设是简单的条件推断能够用if语句: let n = 5; if n < 0 { print!("{} is negative", n); } else if n >