正则替换示例

用于文本转换和数据清洗的常用正则替换模式集合

样本信息

分类
Text Processing
样本数量
13
格式族
text, regex, csv, video

样本概览

用于文本转换和数据清洗的常用正则替换模式集合 This sample set belongs to Text Processing and can be used to test related workflows inside Elysia Tools.

📝 电话号码格式化 regex

🟢 simple ⭐⭐

添加或删除电话号码格式(破折号、括号、空格)

⏱️ 8 min 🏷️ phone, format, number, contact
# Phone Number Formatting Examples
# Patterns for standardizing phone number formats

# --- Add Dashes (1234567890 → 123-456-7890) ---
# Pattern: (\d{3})(\d{3})(\d{4})
# Replacement: $1-$2-$3
# Input: 1234567890
# Output: 123-456-7890

# --- Add Parentheses and Dash (1234567890 → (123) 456-7890) ---
# Pattern: (\d{3})(\d{3})(\d{4})
# Replacement: ($1) $2-$3
# Input: 1234567890
# Output: (123) 456-7890

# --- Remove All Formatting (123-456-7890 → 1234567890) ---
# Pattern: \D
# Replacement: (empty)
# Input: (123) 456-7890
# Output: 1234567890

# --- Add Spaces (1234567890 → 123 456 7890) ---
# Pattern: (\d{3})(\d{3})(\d{4})
# Replacement: $1 $2 $3
# Input: 1234567890
# Output: 123 456 7890

# --- International Format (+11234567890 → +1 123-456-7890) ---
# Pattern: (\+\d{1})(\d{3})(\d{3})(\d{4})
# Replacement: $1 $2-$3-$4
# Input: +11234567890
# Output: +1 123-456-7890

# --- Convert to International (1234567890 → +1-123-456-7890) ---
# Pattern: ^(\d{3})(\d{3})(\d{4})$
# Replacement: +1-$1-$2-$3
# Input: 1234567890
# Output: +1-123-456-7890

# --- Add Extension Support (1234567890 ext 123 → 123-456-7890 x123) ---
# Pattern: (\d{3})(\d{3})(\d{4})(?: ext\.? (\d+))?
# Replacement: $1-$2-$3 x$4
# Input: 1234567890 ext 123
# Output: 123-456-7890 x123

# --- Normalize Separator (123.456.7890 → 123-456-7890) ---
# Pattern: (\d{3})[.\s](\d{3})[.\s](\d{4})
# Replacement: $1-$2-$3
# Input: 123.456.7890
# Output: 123-456-7890

# --- Format with Country Code (11234567890 → +1 (123) 456-7890) ---
# Pattern: (\d{1})(\d{3})(\d{3})(\d{4})
# Replacement: +$1 ($2) $3-$4
# Input: 11234567890
# Output: +1 (123) 456-7890

📝 电子邮件混淆 regex

🟢 simple ⭐⭐

使用星号或占位符隐藏或屏蔽电子邮件地址

⏱️ 8 min 🏷️ email, privacy, obfuscation, masking
# Email Obfuscation Examples
# Patterns for hiding or masking email addresses

# --- Mask All But First Letter ([email protected] → j***@example.com) ---
# Pattern: (\w)(\w+@(\w+\.)*\w+)
# Notes: Use callback to replace group 2 with asterisks
# Input: [email protected]
# Output: j***@example.com

# --- Mask Domain ([email protected] → john@******.com) ---
# Pattern: @(\w+\.)(\w+)
# Notes: Use callback to mask domain name
# Input: [email protected]
# Output: john@******.com

# --- Show First and Last ([email protected] → j***[email protected]) ---
# Pattern: (\w)(\w+)(\w)@
# Notes: Use callback to replace middle with asterisks
# Input: [email protected]
# Output: j***[email protected]

# --- Full Mask ([email protected] → ****@*****.com) ---
# Pattern: (\w+)@(\w+\.?)+\w+
# Notes: Replace each group with asterisks of same length
# Input: [email protected]
# Output: ****@*****.com

# --- Replace with Placeholder ([email protected] → [email hidden]) ---
# Pattern: \b[\w.%+-]+@[\w.-]+\.[A-Z]{2,}\b
# Replacement: [email hidden]
# Input: Contact [email protected]
# Output: Contact [email hidden]

# --- Show Domain Only ([email protected] → ***@example.com) ---
# Pattern: \w+(@[\w.-]+\.[A-Z]{2,})
# Replacement: *$1
# Input: [email protected]
# Output: *@example.com

# --- Mask TLD ([email protected] → john@example.***) ---
# Pattern: @(\w+\.)(\w+)
# Replacement: @$1***
# Input: [email protected]
# Output: john@example.***

# --- Partial Username ([email protected] → jo***@example.com) ---
# Pattern: (\w{2})(\w+)@
# Notes: Use callback to replace rest with asterisks
# Input: [email protected]
# Output: jo***@example.com

# --- Format for Display ([email protected] → john [at] example [dot] com) ---
# Pattern: ([\w.%+-]+)@([\w.-]+)\.([A-Z]{2,})
# Replacement: $1 [at] $2 [dot] $3
# Input: [email protected]
# Output: john [at] example [dot] com

# --- Add Prefix ([email protected] → Email: [email protected]) ---
# Pattern: ([\w.%+-]+@[\w.-]+\.[A-Z]{2,})
# Replacement: Email: $1
# Input: [email protected]
# Output: Email: [email protected]

📝 信用卡屏蔽 regex

🟢 simple ⭐⭐

隐藏敏感信用卡号,仅显示最后4位数字

⏱️ 6 min 🏷️ credit-card, masking, privacy, security
# Credit Card Masking Examples
# Patterns for hiding sensitive credit card numbers

# --- Show Last 4 Digits (1234567890123456 → ****-****-****-3456) ---
# Pattern: \d{12}(\d{4})
# Replacement: ****-****-****-$1
# Input: 1234567890123456
# Output: ****-****-****-3456

# --- Mask All But Last 4 (1234567890123456 • ************3456) ---
# Pattern: \d{12}(\d{4})
# Replacement: ************$1
# Input: 1234567890123456
# Output: ************3456

# --- Mask First 12 with Spaces (1234-5678-9012-3456 • •••• •••• •••• 3456) ---
# Pattern: \d{4}(\d{4})(\d{4})(\d{4})
# Replacement: •••• $1 $2 $3
# Input: 1234567890123456
# Output: •••• 5678 9012 3456

# --- Remove All Digits (1234567890123456 • ••••••••••••••) ---
# Pattern: \d
# Replacement: •
# Input: 1234567890123456
# Output: ••••••••••••••••

# --- Format and Mask (1234567890123456 • **** **** **** 3456) ---
# Pattern: (\d{4})(\d{4})(\d{4})(\d{4})
# Replacement: **** **** **** $4
# Input: 1234567890123456
# Output: **** **** **** 3456

# --- Show Bin and Last 4 (1234567890123456 → 1234******3456) ---
# Pattern: (\d{4})(\d{8})(\d{4})
# Replacement: $1********$3
# Input: 1234567890123456
# Output: 1234********3456

# --- Mask in Sentence (Card: 1234567890123456 • Card: ****3456) ---
# Pattern: \d{12}(\d{4})
# Replacement: ****$1
# Input: Card: 1234567890123456
# Output: Card: ****3456

# --- Add Spaces and Mask (1234567890123456 • •• •• •• 3456) ---
# Pattern: (\d{4})(\d{4})(\d{4})(\d{4})
# Replacement: •• •• •• $4
# Input: 1234567890123456
# Output: •• •• •• 3456

# --- Replace with Placeholder (1234567890123456 • [CARD HIDDEN]) ---
# Pattern: \d{16}
# Replacement: [CARD HIDDEN]
# Input: 1234567890123456
# Output: [CARD HIDDEN]

# --- Mask Groups (1234-5678-9012-3456 • ****-****-****-3456) ---
# Pattern: (\d{4})-(\d{4})-(\d{4})-(\d{4})
# Replacement: ****-****-****-$4
# Input: 1234-5678-9012-3456
# Output: ****-****-****-3456

# --- Partial Mask (1234567890123456 → 1**2**3**4**56) ---
# Pattern: (\d{4})(\d{4})(\d{4})(\d{4})
# Notes: Use callback for custom masking pattern
# Input: 1234567890123456
# Output: 1**2**3**4**56

📝 字符串清理 regex

🟢 simple ⭐⭐

删除多余空格、换行符和特殊字符

⏱️ 8 min 🏷️ cleanup, spaces, sanitization, cleaning
# String Cleanup Examples
# Patterns for removing extra spaces, line breaks, and special characters

# --- Remove Extra Spaces (hello    world → hello world) ---
# Pattern: \s{2,}
# Replacement: ' '
# Input: hello    world
# Output: hello world

# --- Trim Leading Spaces (   hello → hello) ---
# Pattern: ^\s+
# Replacement: (empty)
# Input:    hello
# Output: hello

# --- Trim Trailing Spaces (hello   → hello) ---
# Pattern: \s+$
# Replacement: (empty)
# Input: hello
# Output: hello

# --- Remove All Spaces (hello world → helloworld) ---
# Pattern: \s
# Replacement: (empty)
# Input: hello world
# Output: helloworld

# --- Remove Line Breaks (line1\nline2 → line1line2) ---
# Pattern: [\r\n]+
# Replacement: (empty)
# Input: line1\nline2
# Output: line1line2

# --- Normalize Line Breaks (\r\n → \n) ---
# Pattern: \r\n
# Replacement: \n
# Input: line1\r\nline2
# Output: line1\nline2

# --- Remove Tab Characters ---
# Pattern: \t
# Replacement: ' '
# Input: hello\tworld
# Output: hello world

# --- Remove Non-ASCII Characters ---
# Pattern: [^\x00-\x7F]
# Replacement: (empty)
# Input: café
# Output: caf

# --- Remove Special Characters (hello@world! → helloworld) ---
# Pattern: [^a-zA-Z0-9\s]
# Replacement: (empty)
# Input: hello@world!
# Output: helloworld

# --- Remove Numbers (abc123 → abc) ---
# Pattern: \d
# Replacement: (empty)
# Input: abc123
# Output: abc

# --- Remove Letters (abc123 → 123) ---
# Pattern: [a-zA-Z]
# Replacement: (empty)
# Input: abc123
# Output: 123

# --- Remove Punctuation (Hello, world! → Hello world) ---
# Pattern: [^a-zA-Z0-9\s]
# Replacement: (empty)
# Input: Hello, world!
# Output: Hello world

# --- Remove Duplicate Lines ---
# Pattern: ^(.*?)$\n?\1$
# Replacement: $1
# Input: line1\nline1\nline2
# Output: line1\nline2

# --- Remove Empty Lines ---
# Pattern: ^\s*$
# Replacement: (empty)
# Input: line1\n\nline2
# Output: line1\nline2

# --- Collapse Multiple Lines to One (line1\nline2 → line1 line2) ---
# Pattern: \n
# Replacement: ' '
# Input: line1\nline2
# Output: line1 line2

📝 日期格式转换 regex

🟡 intermediate ⭐⭐⭐

在不同日期格式之间转换(ISO转本地、美国转欧洲等)

⏱️ 10 min 🏷️ date, format, conversion, time
# Date Format Conversion Examples
# Common regex patterns for converting between date formats

# --- ISO to US Format (YYYY-MM-DD → MM/DD/YYYY) ---
# Pattern: (\d{4})-(\d{2})-(\d{2})
# Replacement: $2/$3/$1
# Input: 2024-12-25
# Output: 12/25/2024

# --- ISO to European Format (YYYY-MM-DD → DD.MM.YYYY) ---
# Pattern: (\d{4})-(\d{2})-(\d{2})
# Replacement: $3.$2.$1
# Input: 2024-12-25
# Output: 25.12.2024

# --- US to ISO Format (MM/DD/YYYY → YYYY-MM-DD) ---
# Pattern: (\d{2})/(\d{2})/(\d{4})
# Replacement: $3-$1-$2
# Input: 12/25/2024
# Output: 2024-12-25

# --- European to ISO Format (DD.MM.YYYY → YYYY-MM-DD) ---
# Pattern: (\d{2})\.(\d{2})\.(\d{4})
# Replacement: $3-$2-$1
# Input: 25.12.2024
# Output: 2024-12-25

# --- Text Month to Number (December 25, 2024 → 12/25/2024) ---
# Pattern: (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{1,2}), (\d{4})
# Replacement (needs mapping): Use with callback function for month mapping

# --- Add Time to Date (2024-12-25 → 2024-12-25 00:00:00) ---
# Pattern: ^(\d{4}-\d{2}-\d{2})$
# Replacement: $1 00:00:00
# Input: 2024-12-25
# Output: 2024-12-25 00:00:00

# --- Remove Time from Date (2024-12-25 14:30:00 → 2024-12-25) ---
# Pattern: ^(\d{4}-\d{2}-\d{2}).*$
# Replacement: $1
# Input: 2024-12-25 14:30:00
# Output: 2024-12-25

# --- Convert Month Name to Abbreviation (December → Dec) ---
# Pattern: \b(January|February|March|April|May|June|July|August|September|October|November|December)\b
# Replacement (varies by month): Use with lookup table

# --- Ordinal Dates (December 25th → December 25) ---
# Pattern: (\d{1,2})(st|nd|rd|th)
# Replacement: $1
# Input: December 25th, 2024
# Output: December 25, 2024

📝 文本大小写转换 regex

🟡 intermediate ⭐⭐⭐

使用替换模式更改匹配文本的大小写

⏱️ 12 min 🏷️ case, casing, uppercase, lowercase, text
# Text Casing Examples
# Note: JavaScript regex replace() doesn\'t support case changes in replacement string
# These patterns show what needs to be matched, with notes on implementation

# --- Uppercase First Letter of Each Word ---
# Pattern: \b\w
# Notes: Use callback function: match => match.toUpperCase()
# Input: hello world
# Output: Hello World

# --- Lowercase All Letters ---
# Pattern: .*
# Notes: Better to use .toLowerCase() directly on the string
# Input: HELLO WORLD
# Output: hello world

# --- Uppercase All Letters ---
# Pattern: .*
# Notes: Better to use .toUpperCase() directly on the string
# Input: hello world
# Output: HELLO WORLD

# --- Title Case After Special Characters ---
# Pattern: (?:^|\s|-|\.)\w
# Notes: Use callback function for each match
# Input: hello-world test.example
# Output: Hello-World Test.Example

# --- Lowercase After Period ---
# Pattern: \.\s*(\w)
# Notes: Use callback to lowercase the letter
# Input: Hello. WORLD.
# Output: Hello. World.

# --- Capitalize Sentences ---
# Pattern: (?:^|[.!?]\s+)([a-z])
# Notes: Use callback to capitalize first letter after sentence endings
# Input: hello. world. test.
# Output: Hello. World. Test.

# --- SCREAMING_SNAKE_CASE to camelCase ---
# Pattern: (_)([A-Z])
# Notes: Use callback: match => match[1].toUpperCase()
# Input: SCREAMING_SNAKE_CASE
# Output: screamingSnakeCase

# --- kebab-case to camelCase ---
# Pattern: (-)([a-z])
# Notes: Use callback: match => match.toUpperCase()
# Input: kebab-case-string
# Output: kebabCaseString

# --- camelCase to snake_case ---
# Pattern: ([a-z])([A-Z])
# Replacement: $1_$2
# Then lowercase the result
# Input: camelCaseString
# Output: camel_case_string

# --- PascalCase to snake_case ---
# Pattern: ([A-Z])
# Replacement: _$1 (then trim leading _ and lowercase)
# Input: PascalCaseString
# Output: pascal_case_string

# --- Remove Extra Capitals (hELLO → HELLO) ---
# Pattern: ([A-Z])([a-z])
# Notes: Complex - use callback logic
# Input: hELLO wORLD
# Output: HELLO WORLD

📝 URL标准化 regex

🟡 intermediate ⭐⭐⭐

通过添加协议、删除www、规范化路径来标准化URL

⏱️ 10 min 🏷️ url, web, link, normalization
# URL Normalization Examples
# Patterns for standardizing URL formats

# --- Add HTTPS Protocol (example.com → https://example.com) ---
# Pattern: ^(?!https?://)(.*)
# Replacement: https://$1
# Input: example.com
# Output: https://example.com

# --- Remove www (https://www.example.com → https://example.com) ---
# Pattern: https?://www\.(.*)
# Replacement: https://$1
# Input: https://www.example.com
# Output: https://example.com

# --- Add Trailing Slash (https://example.com → https://example.com/) ---
# Pattern: ^(https?://[^/]+)$
# Replacement: $1/
# Input: https://example.com
# Output: https://example.com/

# --- Remove Trailing Slash (https://example.com/ → https://example.com) ---
# Pattern:^(https?://.+)/$
# Replacement: $1
# Input: https://example.com/
# Output: https://example.com

# --- Convert HTTP to HTTPS (http://example.com → https://example.com) ---
# Pattern: http://(.*)
# Replacement: https://$1
# Input: http://example.com
# Output: https://example.com

# --- Remove Duplicate Slashes (https://example.com//path → https://example.com/path) ---
# Pattern: (?<!:)/{2,}
# Replacement: /
# Input: https://example.com//path
# Output: https://example.com/path

# --- Normalize Path Slashes (https://example.com/path/ → https://example.com/path) ---
# Pattern: (.+)/$
# Replacement: $1
# Input: https://example.com/path/
# Output: https://example.com/path

# --- Remove Fragment (https://example.com#section → https://example.com) ---
# Pattern: ^(.*?)#.*$
# Replacement: $1
# Input: https://example.com#section
# Output: https://example.com

# --- Remove Query Parameters (https://example.com?param=value → https://example.com) ---
# Pattern: ^(.*?)\?.*$
# Replacement: $1
# Input: https://example.com?param=value
# Output: https://example.com

# --- Remove Port Number (https://example.com:8080 → https://example.com) ---
# Pattern: ^(https?://[^/:]+):\d+(.*)$
# Replacement: $1$2
# Input: https://example.com:8080/path
# Output: https://example.com/path

# --- Lowercase Domain (HTTPS://EXAMPLE.COM → https://example.com) ---
# Pattern: ^(https?://)([^/]+)
# Notes: Use callback to lowercase group 2
# Input: HTTPS://EXAMPLE.COM
# Output: https://example.com

📝 HTML标签删除和转换 regex

🟡 intermediate ⭐⭐⭐

删除HTML标签或转换为markdown等格式

⏱️ 12 min 🏷️ html, markdown, conversion, strip
# HTML Tag Removal and Conversion Examples
# Patterns for stripping or converting HTML markup

# --- Remove All HTML Tags ---
# Pattern: <[^>]*>
# Replacement: (empty)
# Input: <p>Hello <b>world</b></p>
# Output: Hello world

# --- Convert <b> to Markdown Bold ---
# Pattern: <b>(.*?)</b>
# Replacement: **$1**
# Input: <b>bold text</b>
# Output: **bold text**

# --- Convert <i> to Markdown Italic ---
# Pattern: <i>(.*?)</i>
# Replacement: *$1*
# Input: <i>italic text</i>
# Output: *italic text*

# --- Convert <h1> to Markdown Header ---
# Pattern: <h1>(.*?)</h1>
# Replacement: # $1
# Input: <h1>Title</h1>
# Output: # Title

# --- Convert <a> to Markdown Link ---
# Pattern: <a href="([^"]*)"[^>]*>(.*?)</a>
# Replacement: [$2]($1)
# Input: <a href="https://example.com">Link</a>
# Output: [Link](https://example.com)

# --- Convert <img> to Markdown Image ---
# Pattern: <img src="([^"]*)"[^>]*alt="([^"]*)"[^>]*/?>
# Replacement: ![$2]($1)
# Input: <img src="pic.jpg" alt="Picture"/>
# Output: ![Picture](pic.jpg)

# --- Remove Script Tags ---
# Pattern: <script[^>]*>.*?</script>
# Replacement: (empty)
# Input: Hello<script>alert('xss')</script>World
# Output: HelloWorld

# --- Remove Style Tags ---
# Pattern: <style[^>]*>.*?</style>
# Replacement: (empty)
# Input: Text<style>body{color:red;}</style>More
# Output: TextMore

# --- Convert <br> to Newline ---
# Pattern: <br\s*/?>|<br>
# Replacement: \n
# Input: Line 1<br>Line 2
# Output: Line 1\nLine 2

# --- Convert <code> to Backticks ---
# Pattern: <code[^>]*>(.*?)</code>
# Replacement: `$1`
# Input: <code>var x = 1;</code>
# Output: `var x = 1;`

# --- Remove HTML Comments ---
# Pattern: <!--.*?-->
# Replacement: (empty)
# Input: Text<!-- comment -->More text
# Output: TextMore text

# --- Convert <ul>/<li> to Markdown List ---
# Pattern: </?ul>|<li>(.*?)</li>
# Replacement (multiple steps): First remove ul tags, then replace li with "  - $1"

# --- Decode HTML Entities (&amp; → &) ---
# Pattern: &amp;
# Replacement: &
# Input: Tom &amp; Jerry
# Output: Tom & Jerry

# --- Decode &lt; and &gt; ---
# Pattern: &lt;|&gt;
# Replacement (two steps): &lt; → <, &gt; → >
# Input: &lt;tag&gt;
# Output: <tag>

📝 数字格式化 regex

🟡 intermediate ⭐⭐⭐

添加千位分隔符、小数格式化和数字标准化

⏱️ 10 min 🏷️ number, format, decimal, separator
# Number Formatting Examples
# Patterns for formatting numbers with separators and decimals

# --- Add Thousand Separators (1000000 → 1,000,000) ---
# Pattern: \B(?=(\d{3})+(?!\d))
# Replacement: ,
# Input: 1000000
# Output: 1,000,000

# --- Remove Thousand Separators (1,000,000 → 1000000) ---
# Pattern: ,
# Replacement: (empty)
# Input: 1,000,000
# Output: 1000000

# --- Add Decimal Point (1000 → 1000.00) ---
# Pattern: ^(\d+)$
# Replacement: $1.00
# Input: 1000
# Output: 1000.00

# --- Format Currency (1000000 → $1,000,000.00) ---
# Pattern: (\d)
# Notes: Multiple step process with callbacks
# Input: 1000000
# Output: $1,000,000.00

# --- Round to 2 Decimals (123.456 → 123.46) ---
# Pattern: ^\d+\.\d{2}(\d)
# Notes: Use callback for rounding logic
# Input: 123.456
# Output: 123.46

# --- Remove Decimals (123.45 → 123) ---
# Pattern: \.(\d+)
# Replacement: (empty)
# Input: 123.45
# Output: 123

# --- Pad Integer with Zeros (123 → 00123) ---
# Pattern: ^(\d+)$
# Notes: Use callback with padStart(5, '0')
# Input: 123
# Output: 00123

# --- Format Percentage (0.85 → 85%) ---
# Pattern: (\d+)\.\d+
# Notes: Use callback to multiply by 100
# Input: 0.85
# Output: 85%

# --- Add Plus Sign for Positive (+100) ---
# Pattern: ^(\d+)$
# Replacement: +$1
# Input: 100
# Output: +100

# --- Format Negative Numbers (-1000 → -1,000) ---
# Pattern: -(\d)(?=(\d{3})+(?!\d))
# Replacement: -$1,
# Input: -1000000
# Output: -1,000,000

# --- Format Phone-like Numbers (1234567 → 123-4567) ---
# Pattern: (\d{3})(\d{4})
# Replacement: $1-$2
# Input: 1234567
# Output: 123-4567

# --- Format SSN (123456789 → 123-45-6789) ---
# Pattern: (\d{3})(\d{2})(\d{4})
# Replacement: $1-$2-$3
# Input: 123456789
# Output: 123-45-6789

# --- Format IP Address (19216811 → 192.168.1.1) ---
# Pattern: (\d{1,3})(\d{1,3})(\d{1,3})(\d{1,3})
# Notes: Requires validation of octet ranges
# Input: 19216811
# Output: 192.168.1.1

📝 Markdown转换 regex

🟡 intermediate ⭐⭐⭐

将markdown转换为HTML或其他格式

⏱️ 12 min 🏷️ markdown, html, conversion, format
# Markdown Conversion Examples
# Patterns for converting markdown syntax to other formats

# --- Bold to HTML (**text** → <strong>text</strong>) ---
# Pattern: \*\*(.*?)\*\*
# Replacement: <strong>$1</strong>
# Input: **bold text**
# Output: <strong>bold text</strong>

# --- Italic to HTML (*text* → <em>text</em>) ---
# Pattern: \*(.*?)\*
# Replacement: <em>$1</em>
# Input: *italic text*
# Output: <em>italic text</em>

# --- Headers to HTML (# Title → <h1>Title</h1>) ---
# Pattern: ^(#{1,6})\s+(.*)$
# Replacement (varies by # count): <h{count}>$2</h{count}>
# Input: # Title
# Output: <h1>Title</h1>

# --- Code Block to HTML (```code``` → <pre><code>code</code></pre>) ---
# Pattern: ```([\s\S]*?)```
# Replacement: <pre><code>$1</code></pre>
# Input: ```code here```
# Output: <pre><code>code here</code></pre>

# --- Inline Code to HTML (`code` → <code>code</code>) ---
# Pattern: `([^`]+)`
# Replacement: <code>$1</code>
# Input: `var x = 1;`
# Output: <code>var x = 1;</code>

# --- Links to HTML ([text](url) → <a href="url">text</a>) ---
# Pattern: \[([^\]]+)\]\(([^)]+)\)
# Replacement: <a href="$2">$1</a>
# Input: [Link](https://example.com)
# Output: <a href="https://example.com">Link</a>

# --- Images to HTML (![alt](url) → <img src="url" alt="alt"/>) ---
# Pattern: !\[([^\]]+)\]\(([^)]+)\)
# Replacement: <img src="$2" alt="$1"/>
# Input: ![Picture](pic.jpg)
# Output: <img src="pic.jpg" alt="Picture"/>

# --- Unordered Lists to HTML (- item → <li>item</li>) ---
# Pattern: ^-\s+(.*)$
# Replacement: <li>$1</li>
# Input: - item
# Output: <li>item</li>

# --- Ordered Lists to HTML (1. item → <li>item</li>) ---
# Pattern: ^\d+\.\s+(.*)$
# Replacement: <li>$1</li>
# Input: 1. item
# Output: <li>item</li>

# --- Blockquotes to HTML (> quote → <blockquote>quote</blockquote>) ---
# Pattern: ^>\s+(.*)$
# Replacement: <blockquote>$1</blockquote>
# Input: > Quote text
# Output: <blockquote>Quote text</blockquote>

# --- Horizontal Rule to HTML (--- → <hr/>) ---
# Pattern: ^-{3,}$
# Replacement: <hr/>
# Input: ---
# Output: <hr/>

# --- Strikethrough to HTML (~~text~~ → <del>text</del>) ---
# Pattern: ~~(.*?)~~
# Replacement: <del>$1</del>
# Input: ~~deleted~~
# Output: <del>deleted</del>

# --- Line Breaks to HTML (line\nline → line<br/>line) ---
# Pattern: \n
# Replacement: <br/>
# Input: Line 1\nLine 2
# Output: Line 1<br/>Line 2

📝 引号标准化 regex

🟡 intermediate ⭐⭐⭐

在直引号、弯引号和其他引号类型之间转换

⏱️ 10 min 🏷️ quotes, normalization, typography
# Quote Normalization Examples
# Patterns for converting between different quote types

# --- Curly to Straight ("text" → "text") ---
# Pattern: ["|"|'|"|']
# Replacement: " or '
# Input: "Hello" and 'world'
# Output: "Hello" and 'world'

# --- Straight to Curly Double ("text" → "text") ---
# Pattern: "(.*?)"
# Notes: Requires context-aware replacement
# Input: "text"
# Output: "text"

# --- Straight to Curly Single ('text' → 'text') ---
# Pattern: '(.*?)'
# Notes: Requires context-aware replacement
# Input: 'text'
# Output: 'text'

# --- Normalize Double Quotes (""text"" → "text") ---
# Pattern: "{2,}
# Replacement: "
# Input: ""hello""
# Output: "hello"

# --- Normalize Single Quotes (''text'' → 'text') ---
# Pattern: '{2,}
# Replacement: '
# Input: ''hello''
# Output: 'hello'

# --- Convert Smart Quotes Left ("text" → "text") ---
# Pattern: "
# Replacement: "
# Input: "Hello"
# Output: "Hello"

# --- Convert Smart Quotes Right ("text" → "text") ---
# Pattern: "
# Replacement: "
# Input: "Hello"
# Output: "Hello"

# --- Convert Smart Single Left ('text' → 'text') ---
# Pattern: '
# Replacement: '
# Input: 'Hello'
# Output: 'Hello'

# --- Convert Smart Single Right ('text' → 'text') ---
# Pattern: '
# Replacement: '
# Input: 'Hello'
# Output: 'Hello'

# --- Remove Quotes Entirely ("text" → text) ---
# Pattern: ["']
# Replacement: (empty)
# Input: "text" and 'more'
# Output: text and more

# --- Escape Quotes for JSON ("text" → "text") ---
# Pattern: "
# Replacement: \"
# Input: He said "hello"
# Output: He said \"hello\"

# --- Unescape Quotes (\"text\" → "text") ---
# Pattern: \\"
# Replacement: "
# Input: \"hello\"
# Output: "hello"

# --- Convert Backticks to Quotes (`text` → "text") ---
# Pattern: `(.*?)`
# Replacement: "$1"
# Input: `text`
# Output: "text"

# --- Standardize Quote Spacing ( text " → text") ---
# Pattern: \s+(["'])
# Replacement: $1
# Input: hello " world "
# Output: hello "world "

📝 路径转换 regex

🟡 intermediate ⭐⭐⭐

在Windows和Unix文件路径之间转换,规范化分隔符

⏱️ 10 min 🏷️ path, filesystem, windows, unix
# Path Conversion Examples
# Patterns for converting between different file path formats

# --- Windows to Unix (C:\\path\\to\\file → /c/path/to/file) ---
# Pattern: ^([A-Z]):\\(.*)$
# Replacement: /$1/$2
# Input: C:\\Users\\name\\file.txt
# Output: /C/Users/name/file.txt

# --- Unix to Windows (/home/user → C:\\home\\user) ---
# Pattern: ^/(.*)$
# Replacement: C:\\$1
# Input: /home/user/file.txt
# Output: C:\home\user\file.txt

# --- Normalize Forward Slashes (path\\to\\file → path/to/file) ---
# Pattern: \\\\
# Replacement: /
# Input: path\\to\\file
# Output: path/to/file

# --- Normalize Back Slashes (path/to/file → path\\to\\file) ---
# Pattern: /
# Replacement: \\\\
# Input: path/to/file
# Output: path\\to\\file

# --- Remove Drive Letter (C:\\path → /path) ---
# Pattern: ^[A-Z]:\\
# Replacement: /
# Input: C:\\Users\\name
# Output: /Users/name

# --- Add Drive Letter (/path → C:\\path) ---
# Pattern: ^/(.*)$
# Replacement: C:\\$1
# Input: /Users/name
# Output: C:\Users\name

# --- Convert Mixed Separators (path/to\\file → path/to/file) ---
# Pattern: [\/]+
# Replacement: /
# Input: path/to\\file
# Output: path/to/file

# --- Remove Trailing Separator (path/to/ → path/to) ---
# Pattern: [\/]+$
# Replacement: (empty)
# Input: path/to/
# Output: path/to

# --- Add Trailing Separator (path/to → path/to/) ---
# Pattern:([^\/]+)$
# Replacement: $1/
# Input: path/to
# Output: path/to/

# --- Remove Duplicate Separators (path//to///file → path/to/file) ---
# Pattern: [\/]{2,}
# Replacement: /
# Input: path//to///file
# Output: path/to/file

# --- UNC to Local Path (\\\\server\\share → //server/share) ---
# Pattern: ^\\\\
# Replacement: //
# Input: \\\\server\\share
# Output: //server/share

# --- Convert Network Path (//server/share → \\\\server\\share) ---
# Pattern: ^
# Replacement: \\\\ (on //server/share patterns)
# Input: //server/share
# Output: \\\\server\\share

# --- Remove Parent References (path/to/../file → path/file) ---
# Pattern: [^/\\]+/\\.\./
# Replacement: (empty)
# Input: path/to/../file
# Output: path/file

# --- Remove Current References (path/./file → path/file) ---
# Pattern: /\\.\./
# Replacement: /
# Input: path/./file
# Output: path/file

📝 高级文本转换 regex

🔴 complex ⭐⭐⭐⭐

包括CSV解析、日志格式化和数据提取在内的复杂转换

⏱️ 15 min 🏷️ advanced, transformation, parsing, data
# Advanced Text Transformation Examples
# Complex patterns for data parsing and transformation

# --- CSV to Pipe Delimited (a,b,c → a|b|c) ---
# Pattern: ,
# Replacement: |
# Input: name,age,city
# Output: name|age|city

# --- Pipe to CSV (a|b|c → a,b,c) ---
# Pattern: \|
# Replacement: ,
# Input: name|age|city
# Output: name,age,city

# --- Extract IPs from Log (Failed IP: 192.168.1.1 → 192.168.1.1) ---
# Pattern: \b(?:\d{1,3}\.){3}\d{1,3}\b
# Notes: Use with match() instead of replace
# Input: User at 192.168.1.1 failed
# Output: 192.168.1.1

# --- Extract URLs from Text ---
# Pattern: https?://[^\s]+
# Notes: Use with match() instead of replace
# Input: Visit https://example.com for more
# Output: https://example.com

# --- Extract Email Addresses ---
# Pattern: \b[\w.%+-]+@[\w.-]+\.[A-Z]{2,}\b
# Notes: Use with match() instead of replace
# Input: Contact [email protected]
# Output: [email protected]

# --- Format Log Timestamp (2024-12-25T14:30:00 → 12/25/2024 2:30 PM) ---
# Pattern: (\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})
# Notes: Use callback for complex date formatting
# Input: 2024-12-25T14:30:00
# Output: 12/25/2024 2:30 PM

# --- Remove ANSI Color Codes ---
# Pattern: \x1b\[[0-9;]*m
# Replacement: (empty)
# Input: \x1b[31mError\x1b[0m
# Output: Error

# --- Extract JSON Keys ---
# Pattern: "([^"]+)":
# Notes: Use with match() for key extraction
# Input: {"name": "John", "age": 30}
# Output: name, age

# --- Base64 Encode Preparation ---
# Pattern: (.)
# Notes: Each char needs btoa() conversion
# Input: Hello
# Output: SGVsbG8=

# --- Reverse String (Hello → olleH) ---
# Pattern: .
# Notes: Split, reverse, join - not pure regex

# --- Remove XML Tags ---
# Pattern: <[^>]+>
# Replacement: (empty)
# Input: <tag>content</tag>
# Output: content

# --- Extract Hashtags (Check #trending → #trending) ---
# Pattern: #[\w]+
# Notes: Use with match() instead of replace
# Input: Check #trending topics
# Output: #trending

# --- Extract Mentions (@user → @user) ---
# Pattern: @[\w]+
# Notes: Use with match() instead of replace
# Input: Hey @john check this
# Output: @john

# --- Format JSON (compact → pretty) ---
# Notes: Use JSON.stringify(obj, null, 2)
# Input: {"a":1,"b":2}
# Output: {\n  "a": 1,\n  "b": 2\n}

# --- Minify JSON (pretty → compact) ---
# Notes: Use JSON.stringify(obj)
# Input: {\n  "a": 1\n}
# Output: {"a":1}