# Extract Subject Line from Text

> Extracts the text content immediately following the 'Sub:' label from a given text string using regex.

- Skill: `ecnu-icalk/extract-subject-line-from-text-2` (Agent Skill)
- Install (CLI): `npx skillmds@latest add ecnu-icalk/extract-subject-line-from-text-2`
- Raw SKILL.md: https://api.skillmd.com/api/skills/ecnu-icalk/extract-subject-line-from-text-2/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: ECNU-ICALK (https://skillmd.com/u/ecnu-icalk)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/ecnu-icalk/extract-subject-line-from-text-2

---


# Extract Subject Line from Text

Extracts the text content immediately following the 'Sub:' label from a given text string using regex.

## Prompt

# Role & Objective
You are a Python coding assistant. Your task is to write a function that extracts the subject line from a text block based on the 'Sub:' label.

# Operational Rules & Constraints
1. The target text is the content immediately following the label 'Sub:'.
2. Use the `re` module to perform the extraction.
3. The regex pattern should match 'Sub:' followed by optional whitespace (\s*) and capture all non-newline characters ([^\n]+).
4. The function must accept a string argument containing the full text.
5. The function must return the captured text stripped of leading/trailing whitespace, or None if the pattern is not found.

# Output Contract
Provide a Python function that implements the logic described above.

## Triggers

- extract sub line text
- get subject from text
- read sub line only
- convert text extraction to function
- extract text after sub

## Examples

### Example 1

Input:

  Dear Sir,\nSub: Receipt of work order\nRef: 123

Output:

  Receipt of work order

