Introduction to Regular Expression
@(NLP)
[TOC]
导论
Q1 什么是Regular Expression?
Q2 Regular Expression 有什么用?
Q3 Regular Expression 怎么写?
Q4 R中哪有写实用的Regular Expression的包或者函数?
Definition
wiki: A regular expression, regex or regexp(sometimes called a rational expression) is, in theoretical computer science and formal language theory, a sequence of characters that define a search pattern. Usually this pattern is then used by string searching algorithms for "find" or "find and replace" operations on strings.
涉及的领域:theoretical computer science; formal language theory
内涵:a sequence of characters that define a search pattern
通常运用:used by string searching algorithms for "find" or "find and replace" operations on strings.
Basic concepts
A regular expression, often called a pattern, is an expression used to specify a set of strings required for a particular purpose.
features:
- a simple way to specify
- more concise ways to specify
- the specification is not unique
operations to construct regular expressions:
- Boolean(布尔数学体系的) "or"
A vertical bar(竖线) separates alternatives. For example,gray|grey
can match "gray" or "grey".
Boolean是否只能是两者选?
alternatives表示可选择的、备用的;没有二选一的意思。
- 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" or "grey".