{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/regular-expressions/",
  "atlas": "https://www.pystone.net/?node=regular-expressions#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/regular-expressions.md",
  "context": "https://www.pystone.net/notes/regular-expressions.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:regular-expressions",
  "slug": "regular-expressions",
  "title": "正则表达式",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "正则表达式",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "6b0d6b478ba6de1c2eae084318f234f2cf030e8a92be71b36db1f6f1499b4eac",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "正则表达式",
      "anchor": "正则表达式",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F"
    },
    {
      "depth": 2,
      "text": "概念",
      "anchor": "概念",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E6%A6%82%E5%BF%B5"
    },
    {
      "depth": 3,
      "text": "应用",
      "anchor": "应用",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E5%BA%94%E7%94%A8"
    },
    {
      "depth": 2,
      "text": "语法",
      "anchor": "语法",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E8%AF%AD%E6%B3%95"
    },
    {
      "depth": 3,
      "text": "普通字符",
      "anchor": "普通字符",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E6%99%AE%E9%80%9A%E5%AD%97%E7%AC%A6"
    },
    {
      "depth": 3,
      "text": "非打印字符",
      "anchor": "非打印字符",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E9%9D%9E%E6%89%93%E5%8D%B0%E5%AD%97%E7%AC%A6"
    },
    {
      "depth": 3,
      "text": "特殊字符",
      "anchor": "特殊字符",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E7%89%B9%E6%AE%8A%E5%AD%97%E7%AC%A6"
    },
    {
      "depth": 3,
      "text": "限定符",
      "anchor": "限定符",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E9%99%90%E5%AE%9A%E7%AC%A6"
    },
    {
      "depth": 3,
      "text": "定位符",
      "anchor": "定位符",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E5%AE%9A%E4%BD%8D%E7%AC%A6"
    },
    {
      "depth": 3,
      "text": "选择、反向引用等操作",
      "anchor": "选择反向引用等操作",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E9%80%89%E6%8B%A9%E5%8F%8D%E5%90%91%E5%BC%95%E7%94%A8%E7%AD%89%E6%93%8D%E4%BD%9C"
    },
    {
      "depth": 2,
      "text": "修饰符（标记）",
      "anchor": "修饰符标记",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E4%BF%AE%E9%A5%B0%E7%AC%A6%E6%A0%87%E8%AE%B0"
    },
    {
      "depth": 2,
      "text": "元字符列表",
      "anchor": "元字符列表",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E5%85%83%E5%AD%97%E7%AC%A6%E5%88%97%E8%A1%A8"
    },
    {
      "depth": 2,
      "text": "运算符优先级",
      "anchor": "运算符优先级",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E8%BF%90%E7%AE%97%E7%AC%A6%E4%BC%98%E5%85%88%E7%BA%A7"
    },
    {
      "depth": 2,
      "text": "匹配规则",
      "anchor": "匹配规则",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E5%8C%B9%E9%85%8D%E8%A7%84%E5%88%99"
    },
    {
      "depth": 3,
      "text": "字符簇",
      "anchor": "字符簇",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E5%AD%97%E7%AC%A6%E7%B0%87"
    },
    {
      "depth": 2,
      "text": "应用示例",
      "anchor": "应用示例",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E5%BA%94%E7%94%A8%E7%A4%BA%E4%BE%8B"
    },
    {
      "depth": 3,
      "text": "匹配两个特殊字符中间的内容",
      "anchor": "匹配两个特殊字符中间的内容",
      "citation": "https://www.pystone.net/notes/regular-expressions/#%E5%8C%B9%E9%85%8D%E4%B8%A4%E4%B8%AA%E7%89%B9%E6%AE%8A%E5%AD%97%E7%AC%A6%E4%B8%AD%E9%97%B4%E7%9A%84%E5%86%85%E5%AE%B9"
    },
    {
      "depth": 2,
      "text": "CSRegular Expression的使用",
      "anchor": "csregular-expression的使用",
      "citation": "https://www.pystone.net/notes/regular-expressions/#csregular-expression%E7%9A%84%E4%BD%BF%E7%94%A8"
    },
    {
      "depth": 2,
      "text": "Ref",
      "anchor": "ref",
      "citation": "https://www.pystone.net/notes/regular-expressions/#ref"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:systems-and-network-security",
      "title": "系统基础与网络安全",
      "url": "https://www.pystone.net/notes/systems-and-network-security/",
      "atlas": "https://www.pystone.net/?node=systems-and-network-security#knowledge-atlas",
      "label": "系统基础与网络安全",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "计算机与操作系统中的“正则表达式”导航项",
      "citation": "https://www.pystone.net/notes/systems-and-network-security/#%E8%AE%A1%E7%AE%97%E6%9C%BA%E4%B8%8E%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F"
    }
  ],
  "contentMarkdown": "# 正则表达式\n\n> 创建时间：2020/8/31 12:20\n\n  * 正则表达式\n    * 概念\n      * 应用\n    * 语法\n      * 普通字符\n      * 非打印字符\n      * 特殊字符\n      * 限定符\n      * 定位符\n      * 选择、反向引用等操作\n    * 修饰符（标记）\n    * 元字符列表\n    * 运算符优先级\n    * 匹配规则\n      * 字符簇\n    * 应用示例\n      * 匹配两个特殊字符中间的内容\n    * CSRegular Expression的使用\n    * Ref\n\n## 概念\n\n正则表达式(Regular Expression)是一种文本模式，包括普通字符（例如，a 到 z 之间的字母）和特殊字符（称为”元字符”）。\n正则表达式使用单个字符串来描述、匹配一系列匹配某个句法规则的字符串。\n\n> 工具：\n>  <https://regex101.com/>\n>  <http://c.runoob.com/front-end/854>\n\n### 应用\n\n  * 测试字符串内的模式。\n例如，可以测试输入字符串，以查看字符串内是否出现电话号码模式或信用卡号码模式。这称为数据验证。\n\n  * 替换文本。\n可以使用正则表达式来识别文档中的特定文本，完全删除该文本或者用其他文本替换它。\n\n  * 基于模式匹配从字符串中提取子字符串。\n可以查找文档内或输入域内特定的文本。\n\n## 语法\n\n‘+’ 号代表前面的字符必须至少出现一次（1次或多次）。\n‘*’ 号代表前面的字符可以不出现，也可以出现一次或者多次（0次、或1次、或多次）。\n‘?’ 问号代表前面的字符最多只可以出现一次（0次、或1次）。\n\n### 普通字符\n\n```xml\npublic class AGenericClass&lt;T&gt; where T : IComparable&lt;T&gt; { }\n\n```\n\n### 非打印字符\n\n```xml\npublic class AGenericClass&lt;T&gt; where T : IComparable&lt;T&gt; { }\n\n```\n\n### 特殊字符\n\n> 许多元字符要求在试图匹配它们时特别对待。若要匹配这些特殊字符，必须首先使字符”转义”，即，将反斜杠字符\\ 放在它们前面。\n\n```xml\npublic class AGenericClass&lt;T&gt; where T : IComparable&lt;T&gt; { }\n\n```\n\n### 限定符\n\n指定正则表达式的一个给定组件必须要出现多少次才能满足匹配。\n\n```xml\npublic class AGenericClass&lt;T&gt; where T : IComparable&lt;T&gt; { }\n\n```\n\n‘*’ 和 ‘+’ 限定符都是贪婪的，因为它们会尽可能多的匹配文字，只有在它们的后面加上一个 ? 就可以实现非贪婪或最小匹配。\n\n### 定位符\n\n^\n$\n\\b 匹配一个单词边界，即字与空格间的位置。\n\\B 非单词边界匹配。\n\n### 选择、反向引用等操作\n\n<https://www.runoob.com/regexp/regexp-syntax.html>\n\n## 修饰符（标记）\n\n正则表达式的标记用于指定额外的匹配策略。位于表达式之外。`/pattern/flags`\ni ignore - 不区分大小写\ng global - 全局匹配\nm more - 多行匹配\ns 特殊字符圆点 . 中包含换行符 \\n\n\n## 元字符列表\n\n<https://www.runoob.com/regexp/regexp-metachar.html>\n\n## 运算符优先级\n\n\\ 转义符\n(), (?:), (?=), [] 圆括号和方括号\n*, +, ?, {n}, {n,}, {n,m} 限定符\n^, $, \\任何元字符、任何字符 定位点和序列（即：位置和顺序）\n|\n\n> 字符具有高于替换运算符的优先级，使得”m|food”匹配”m”或”food”。若要匹配”mood”或”food”，请使用括号创建子表达式，从而产生”(m|f)ood”。\n\n## 匹配规则\n\n### 字符簇\n\n```xml\npublic class AGenericClass&lt;T&gt; where T : IComparable&lt;T&gt; { }\n\n```\n\n## 应用示例\n\n### 匹配两个特殊字符中间的内容\n\n表达式: A.*?B（“.“表示任意字符，“？”表示匹配0个或多个）\n示例: Abaidu.comB\n结果: Awww.apizl.comB\n匹配两个字符串A与B中间的字符串包含A但是不包含B：\n表达式: A.*?(?=B)\n示例: Awww.apizl.comB\n结果: Awww.apizl.com\n匹配两个字符串A与B中间的字符串且不包含A与B：\n表达式: (?<=A).*?(?=B)\n示例: Awww.baidu.comB\n结果: www.baidu.com\n\n> (?=pattern)：非获取匹配，正向肯定预查，在任何匹配pattern的字符串开始处匹配查找字符串，该匹配不需要获取供以后使用。例如，“Windows(?=95|98|NT|2000)”能匹配“Windows2000”中的“Windows”，但不能匹配“Windows3.1”中的“Windows”。预查不消耗字符，也就是说，在一个匹配发生后，在最后一次匹配之后立即开始下一次匹配的搜索，而不是从包含预查的字符之后开始。\n>\n> (?<=pattern)：非获取匹配，反向肯定预查，与正向肯定预查类似，只是方向相反。例如，“(?<=95|98|NT|2000)Windows”能匹配“2000Windows”中的“Windows”，但不能匹配“3.1Windows”中的“Windows”。\n\n## CSRegular Expression的使用\n\n<https://www.runoob.com/csharp/csharp-regular-expressions.html>\n\n## Ref\n\n<https://www.runoob.com/regexp/regexp-intro.html>\n<https://www.cnblogs.com/liaods/p/10049730.html>\n"
}
