<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>正则表达式 on 老张开工了</title>
    <link>/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/</link>
    <description>Recent content in 正则表达式 on 老张开工了</description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    <lastBuildDate>Fri, 22 May 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>正则表达式从入门到精通</title>
      <link>/posts/2026/05/regex/</link>
      <pubDate>Fri, 22 May 2026 00:00:00 +0000</pubDate>
      <guid>/posts/2026/05/regex/</guid>
      <description>什么是正则表达式 正则表达式（Regular Expression，简称 regex）是一种用于匹配字符串中字符组合的模式。它提供了一种强大、灵活且高效的方式来处理文本——搜索、匹配、替换和提取数据。&#xA;Python 的 re 模块提供了完整的正则表达式支持。在本章中，我们将从基础语法开始，逐步深入到实战应用。&#xA;第一个正则表达式 import re # 检查字符串中是否包含 &amp;#34;python&amp;#34; text = &amp;#34;我喜欢 Python 编程语言&amp;#34; pattern = r&amp;#34;Python&amp;#34; result = re.search(pattern, text) if result: print(f&amp;#34;找到了: {result.group()}&amp;#34;) # 输出: 找到了: Python 这里的 r&amp;quot;Python&amp;quot; 中的 r 表示原始字符串（raw string），它会告诉 Python 不要处理字符串中的反斜杠转义，这对于正则表达式至关重要。&#xA;re 模块的核心函数 re.match() — 从开头匹配 re.match() 从字符串的起始位置开始匹配，如果开头不匹配则返回 None：&#xA;import re text = &amp;#34;Python 是一门优秀的编程语言&amp;#34; # 从开头匹配 match = re.match(r&amp;#34;Python&amp;#34;, text) if match: print(match.group()) # Python # 不从开头匹配则失败 match = re.</description>
    </item>
  </channel>
</rss>
