再看正则表达式
下面的介绍介绍,来自wikipedia:
In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. Regular expressions (abbreviated as regex or regexp, with plural forms regexes, regexps, or regexen) are written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.
Many modern computing systems provide wildcard characters in matching filenames from a file system. This is a core capability of many command-line shells and is also known as globbing. Wildcards differ from regular expressions in that they generally only express very limited forms of alternation.(这里提到了和通配符的不同,正则表达式的表达能力比通配符强多了)
Alternation
- A vertical bar separates alternatives. For example,
gray|grey
can match "gray" or "grey". - Grouping
- Parentheses are used to define the scope and precedence of the operators (among other uses). For example,
gray|grey
andgr(a|e)y
are equivalent patterns which both describe the set of "gray" and "grey". - Quantification
- A quantifier after a token (such as a character) or group specifies how often that preceding element is allowed to occur. The most common quantifiers are
?
,*
, and+
.
-
?
The question mark indicates there is zero or one of the preceding element. For example, colou?r
matches both "color" and "colour".*
The asterisk indicates there are zero or more of the preceding element. For example, ab*c
matches "ac", "abc", "abbc", "abbbc", and so on.+
The plus sign indicates that there is one or more of the preceding element. For example, ab+c
matches "abc", "abbc", "abbbc", and so on, but not "ac".
不同的软件、语言的正则表达式语法不尽相同,打算专攻一下perl和java。
Reference:
http://en.wikipedia.org/wiki/Regular_expression ( General concept)
http://www.regular-expressions.info/ (Provide different languages format, very good!)
http://www.regular-expressions.info/reference.html (Basic Syntax)
http://docs.python.org/lib/re-syntax.html (in Python)
http://www.regular-expressions.info/java.html (in Java)
http://regexlib.com/ ( library for use)
P: blog的访问量也即将突破10万了,纪念一下
【推荐】中国电信天翼云云端翼购节,2核2G云服务器一口价38元/年
【推荐】博客园携手 AI 驱动开发工具商 Chat2DB 推出联合终身会员
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步