<?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%96%87%E6%9C%AC%E5%A4%84%E7%90%86/</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%96%87%E6%9C%AC%E5%A4%84%E7%90%86/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>
    <item>
      <title>字符串操作深入</title>
      <link>/posts/2026/05/string-operations/</link>
      <pubDate>Mon, 04 May 2026 00:00:00 +0000</pubDate>
      <guid>/posts/2026/05/string-operations/</guid>
      <description>字符串是 Python 中使用最频繁的数据类型之一。无论是从用户获取输入、读写文件、处理网络数据，还是生成报告，字符串操作无处不在。Python 的字符串处理能力非常强大，掌握好字符串操作能让你在处理文本时事半功倍。&#xA;字符串基础 创建字符串 # 四种创建方式 s1 = &amp;#39;单引号字符串&amp;#39; s2 = &amp;#34;双引号字符串&amp;#34; s3 = &amp;#39;&amp;#39;&amp;#39;三单引号 支持换行&amp;#39;&amp;#39;&amp;#39; s4 = &amp;#34;&amp;#34;&amp;#34;三双引号 也支持换行&amp;#34;&amp;#34;&amp;#34; print(s1) # 单引号字符串 print(s2) # 双引号字符串 print(s3) # 三单引号\n支持换行 单引号 vs 双引号 两种方式完全等价，选择标准是方便性：&#xA;# 字符串本身包含单引号时，用双引号更省事 msg1 = &amp;#34;It&amp;#39;s a beautiful day&amp;#34; # 不用转义 msg2 = &amp;#39;It\&amp;#39;s a beautiful day&amp;#39; # 需要转义 # 字符串本身包含双引号时，用单引号更省事 msg3 = &amp;#39;他说：&amp;#34;你好&amp;#34;&amp;#39; msg4 = &amp;#34;他说：\&amp;#34;你好\&amp;#34;&amp;#34; 字符串索引与切片 索引 Python 字符串支持正索引（从 0 开始）和负索引（从 -1 开始）：&#xA;text = &amp;#34;Python&amp;#34; # 正索引（从 0 到 length-1） print(text[0]) # P print(text[1]) # y print(text[5]) # n # 负索引（从 -1 到 -length） print(text[-1]) # n（最后一个字符） print(text[-2]) # o（倒数第二个） print(text[-6]) # P（第一个字符） # 索引越界 # print(text[100]) # IndexError: string index out of range 切片（Slicing） 切片是 Python 最强大的特性之一，语法为 [start:stop:step]：</description>
    </item>
  </channel>
</rss>
