Introduction to Regular Expression
@(NLP)
[TOC]
導(dǎo)論
Q1 什么是Regular Expression?
Q2 Regular Expression 有什么用?
Q3 Regular Expression 怎么寫?
Q4 R中哪有寫實(shí)用的Regular Expression的包或者函數(shù)?
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.
涉及的領(lǐng)域:theoretical computer science; formal language theory
內(nèi)涵:a sequence of characters that define a search pattern
通常運(yùn)用: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(布爾數(shù)學(xué)體系的) "or"
A vertical bar(豎線) separates alternatives. For example,gray|greycan match "gray" or "grey".
Boolean是否只能是兩者選?
alternatives表示可選擇的、備用的;沒(méi)有二選一的意思。
- Grouping
Parentheses(圓括號(hào)) are used to define the scope(范圍) and precedence(位次) of the operators (among other uses).For example,gray|greyandgr(a|e)yare equivalent patterns which both describe the set of "gray" or "grey".