首页 > 其他分享 >Regular Expression

Regular Expression

时间:2023-09-07 09:34:38浏览次数:36  
标签:abc matches character any Matches Regular Expression example

POSIX basic and extended[edit]

In the POSIX standard, Basic Regular Syntax (BRE) requires that the metacharacters ( ) and { } be designated \(\) and \{\}, whereas Extended Regular Syntax (ERE) does not.

MetacharacterDescription
^ Matches the starting position within the string. In line-based tools, it matches the starting position of any line.
. Matches any single character (many applications exclude newlines, and exactly which characters are considered newlines is flavor-, character-encoding-, and platform-specific, but it is safe to assume that the line feed character is included). Within POSIX bracket expressions, the dot character matches a literal dot. For example, a.c matches "abc", etc., but [a.c] matches only "a", ".", or "c".
[ ] A bracket expression. Matches a single character that is contained within the brackets. For example, [abc] matches "a", "b", or "c". [a-z] specifies a range which matches any lowercase letter from "a" to "z". These forms can be mixed: [abcx-z] matches "a", "b", "c", "x", "y", or "z", as does [a-cx-z].

The - character is treated as a literal character if it is the last or the first (after the ^, if present) character within the brackets: [abc-][-abc]. Note that backslash escapes are not allowed. The ] character can be included in a bracket expression if it is the first (after the ^) character: []abc].

[^ ] Matches a single character that is not contained within the brackets. For example, [^abc] matches any character other than "a", "b", or "c". [^a-z] matches any single character that is not a lowercase letter from "a" to "z". Likewise, literal characters and ranges can be mixed.
$ Matches the ending position of the string or the position just before a string-ending newline. In line-based tools, it matches the ending position of any line.
( ) Defines a marked subexpression. The string matched within the parentheses can be recalled later (see the next entry, \n). A marked subexpression is also called a block or capturing group. BRE mode requires \( \).
\n Matches what the nth marked subexpression matched, where n is a digit from 1 to 9. This construct is vaguely defined in the POSIX.2 standard. Some tools allow referencing more than nine capturing groups. Also known as a backreference. backreferences are only supported in BRE mode
* Matches the preceding element zero or more times. For example, ab*c matches "ac", "abc", "abbbc", etc. [xyz]* matches "", "x", "y", "z", "zx", "zyx", "xyzzy", and so on. (ab)* matches "", "ab", "abab", "ababab", and so on.
{m,n} Matches the preceding element at least m and not more than n times. For example, a{3,5} matches only "aaa", "aaaa", and "aaaaa". This is not found in a few older instances of regexes. BRE mode requires \{m,n\}.

 

POSIX extended[edit]

The meaning of metacharacters escaped with a backslash is reversed for some characters in the POSIX Extended Regular Expression (ERE) syntax. With this syntax, a backslash causes the metacharacter to be treated as a literal character. So, for example, \( \) is now ( ) and \{ \} is now { }. Additionally, support is removed for \n backreferences and the following metacharacters are added:

MetacharacterDescription
? Matches the preceding element zero or one time. For example, ab?c matches only "ac" or "abc".
+ Matches the preceding element one or more times. For example, ab+c matches "abc", "abbc", "abbbc", and so on, but not "ac".
| The choice (also known as alternation or set union) operator matches either the expression before or the expression after the operator. For example, abc|def matches "abc" or "def".

标签:abc,matches,character,any,Matches,Regular,Expression,example
From: https://www.cnblogs.com/zhangzhihui/p/17683976.html

相关文章

  • Proj CDeepFuzz Paper Reading: Invariance-inducing regularization using worst-cas
    Abstract本文:Task:1.proveinvariance-inducingregularizerscanincreasepredictiveaccuracyforworst-casespatialtransformations2.provethatonadversarialexamplesfromtransformationgroupsintheinfinitedatalimitrobusttrainingcanalsoimpro......
  • LuoguP7637 [BalticOI 2006 Day 1] BITWISE EXPRESSIONS
    题目大意给定\(N\)对数据,每对数据包含两个整数\(A_i\)和\(B_i\),表示这一对数据的\(v_i\)的范围:\(A_i\leqv_i\leqB_i\)。又将这\(N\)对数据分为\(P\)组,其中\(K_i\)表示第\(i\)组数据中有多少对数据。我们设第\(i\)组数据中将所有数按位与的结果为\(X_i\),求......
  • JavaScript regular expression in Actions All In One
    JavaScriptregularexpressioninActionsAllInOneJavaScript正则表达式实战demos在字符串中匹配多组数据conststr='lines[0][config][options][343]';constreg=/\[([0-9]+|[a-z]+|[A-Z]+)\]/g;constgroups=[];str.replaceAll(reg,group=>{letv......
  • AOP源码解析:AspectJExpressionPointcutAdvisor类
    先看看AspectJExpressionPointcutAdvisor的类图再了解一下切点(Pointcut)表达式,它指定触发advice的方法,可以精确到返回参数,参数类型,方法名1packageconcert;23publicinterfacePerformance{4voidperform();5}AspectJExpressionPointcutAdvisor源码,官......
  • [LeetCode][10]regular-expression-matching
    ContentGivenaninputstrings andapatternp,implementregularexpressionmatchingwithsupportfor'.'and'*'where:'.'Matchesanysinglecharacter.​​​​'*'Matcheszeroormoreoftheprecedingelement.T......
  • LeetCode[10]RegularExpressionMatching
    ContentGivenaninputstrings andapatternp,implementregularexpressionmatchingwithsupportfor'.'and'*'where:'.'Matchesanysinglecharacter.​​​​'*'Matcheszeroormoreoftheprecedingelement.T......
  • [10]RegularExpressionMatching
    ContentGivenaninputstrings andapatternp,implementregularexpressionmatchingwithsupportfor'.'and'*'where:'.'Matchesanysinglecharacter.​​​​'*'Matcheszeroormoreoftheprecedingelement.T......
  • 数字基因表达谱(Digital Gene Expression Profiling,DGE)
    数字基因表达谱(DigitalGeneExpressionProfiling,DGE) 利用新一代高通量测序技术和高性能计算分析技术,能够全面、经济、快速地检测某一物种特定组织在特定状态下的基因表达情况。 数字基因表达谱已被广泛应用于基础科学研究、医学研究和药物研发等领域。 楼主应该是......
  • @ConditionalOnExpression 注解
    @ConditionalOnExpression注解如果有一个基类,它下面有子类实现比如v1,v2,v3三个子类,但使用的时候,springboot服务启动的时候,只想指定用其中的一种,这种情况要怎样做呢?比如基类:RentPlan出租计划它有几个实现类RentPlanV1,RentPlanV2,RentPlanV3这三个实现类,希望用相同......
  • cannot import name '_BindParamClause' from 'sqlalchemy.sql.expression'
    python3.8安装环境组件正常安装运行 flaskdbinit报错 cannotimportname'_BindParamClause'from'sqlalchemy.sql.expression' 问题原因-未知 解决方案更新alembic组件版本pipinstall--upgradealembic 问题解决 ......