Elysia Tools

在一个清晰的工作台里浏览工具、案例、可视化和主题指南。

热门分类

专题

语言
ZHDERUPTENFRES

Elysia Tools

导航

文本处理

正则表达式命名捕获组

使用命名捕获组从文本中提取结构化数据的正则表达式模式集合。命名组通过为捕获的部分分配有意义的名称,使模式更易读和更易维护。

案例

这个案例集合中的条目

文本regex简单

日期解析模式

使用命名捕获组从各种日期格式中提取日期组件(年、月、日)

难度

3/10

预计时间

5 min

标签

date, parsing, datetime, formatting

regex
# Date Parsing with Named Groups
# Extract year, month, and day from date strings

# ISO 8601 Format (YYYY-MM-DD)
# Pattern: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})
# Input: 2025-01-16
# Groups: year=2025, month=01, day=16
(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})

# US Format (MM/DD/YYYY)
# Pattern: (?<month>\d{2})/(?<day>\d{2})/(?<year>\d{4})
# Input: 01/16/2025
# Groups: month=01, day=16, year=2025
(?<month>\d{2})/(?<day>\d{2})/(?<year>\d{4})

# European Format (DD.MM.YYYY)
# Pattern: (?<day>\d{2})\.(?<month>\d{2})\.(?<year>\d{4})
# Input: 16.01.2025
# Groups: day=16, month=01, year=2025
(?<day>\d{2})\.(?<month>\d{2})\.(?<year>\d{4})

# Textual Month (YYYY-Mon-DD)
# Pattern: (?<year>\d{4})-(?<month>[A-Za-z]{3})-(?<day>\d{2})
# Input: 2025-Jan-16
# Groups: year=2025, month=Jan, day=16
(?<year>\d{4})-(?<month>[A-Za-z]{3})-(?<day>\d{2})

# Full Month Name
# Pattern: (?<month>[A-Za-z]+) (?<day>\d{1,2}), (?<year>\d{4})
# Input: January 16, 2025
# Groups: month=January, day=16, year=2025
(?<month>[A-Za-z]+) (?<day>\d{1,2}), (?<year>\d{4})

# ISO with Time
# Pattern: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})T(?<hour>\d{2}):(?<minute>\d{2})
# Input: 2025-01-16T14:30
# Groups: year=2025, month=01, day=16, hour=14, minute=30
(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})T(?<hour>\d{2}):(?<minute>\d{2})
文本regex简单

时间解析模式

从各种时间格式中提取时间组件(时、分、秒)

难度

3/10

预计时间

5 min

标签

time, parsing, datetime, formatting

regex
# Time Parsing with Named Groups
# Extract hour, minute, second from time strings

# 24-Hour Format (HH:MM:SS)
# Pattern: (?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})
# Input: 14:30:45
# Groups: hour=14, minute=30, second=45
(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})

# 12-Hour Format with AM/PM
# Pattern: (?<hour>\d{1,2}):(?<minute>\d{2}):(?<second>\d{2}) (?<ampm>[AP]M)
# Input: 2:30:45 PM
# Groups: hour=2, minute=30, second=45, ampm=PM
(?<hour>\d{1,2}):(?<minute>\d{2}):(?<second>\d{2}) (?<ampm>[AP]M)

# Hours and Minutes Only
# Pattern: (?<hour>\d{2}):(?<minute>\d{2})
# Input: 14:30
# Groups: hour=14, minute=30
(?<hour>\d{2}):(?<minute>\d{2})

# Time with Milliseconds
# Pattern: (?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})\.(?<ms>\d{3})
# Input: 14:30:45.123
# Groups: hour=14, minute=30, second=45, ms=123
(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})\.(?<ms>\d{3})

# ISO 8601 Time
# Pattern: (?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})(?<tz>[+-]\d{2}:\d{2})
# Input: 14:30:45+05:30
# Groups: hour=14, minute=30, second=45, tz=+05:30
(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})(?<tz>[+-]\d{2}:\d{2})
文本regex中等

URL解析模式

从URL中提取URL组件(协议、域名、路径、查询、片段)

难度

6/10

预计时间

10 min

标签

url, parsing, web, http

regex
# URL Parsing with Named Groups
# Extract protocol, domain, path, query, fragment from URLs

# Basic URL Structure
# Pattern: (?<protocol>https?)://(?<domain>[^/]+)(?<path>/[^?#]*)?(?:\?(?<query>[^#]*))?(?:#(?<fragment>.*))?
# Input: https://example.com/path/to/page?param=value#section
# Groups: protocol=https, domain=example.com, path=/path/to/page, query=param=value, fragment=section
(?<protocol>https?)://(?<domain>[^/]+)(?<path>/[^?#]*)?(?:\?(?<query>[^#]*))?(?:#(?<fragment>.*))?

# URL with Subdomain
# Pattern: (?<protocol>https?)://(?<subdomain>[^/.]+)\.(?<domain>[^/]+)(?<path>/.*)
# Input: https://blog.example.com/post/123
# Groups: protocol=https, subdomain=blog, domain=example.com, path=/post/123
(?<protocol>https?)://(?<subdomain>[^/.]+)\.(?<domain>[^/]+)(?<path>/.*)

# URL with Port
# Pattern: (?<protocol>https?)://(?<domain>[^/:]+):(?<port>\d+)(?<path>/.*)
# Input: http://localhost:8080/api/users
# Groups: protocol=http, domain=localhost, port=8080, path=/api/users
(?<protocol>https?)://(?<domain>[^/:]+):(?<port>\d+)(?<path>/.*)

# URL with Auth (rare)
# Pattern: (?<protocol>https?)://(?<user>[^:]+):(?<pass>[^@]+)@(?<domain>[^/]+)
# Input: https://admin:password@example.com
# Groups: protocol=https, user=admin, pass=password, domain=example.com
(?<protocol>https?)://(?<user>[^:]+):(?<pass>[^@]+)@(?<domain>[^/]+)

# Extract Domain Parts
# Pattern: (?<protocol>https?)://(?<subdomain>[^.]+)\.(?<domain>[^.]+)\.(?<tld>[^.]+)
# Input: https://www.example.com
# Groups: protocol=https, subdomain=www, domain=example, tld=com
(?<protocol>https?)://(?<subdomain>[^.]+)\.(?<domain>[^.]+)\.(?<tld>[^.]+)
文本regex中等

电子邮件解析模式

从电子邮件地址中提取电子邮件组件(本地部分、域名、顶级域名)

难度

5/10

预计时间

8 min

标签

email, parsing, validation, contact

regex
# Email Parsing with Named Groups
# Extract local part, domain, and TLD from email addresses

# Basic Email Structure
# Pattern: (?<local>[^@]+)@(?<domain>[^.]+)\.(?<tld>[^@]+)
# Input: user@example.com
# Groups: local=user, domain=example, tld=com
(?<local>[^@]+)@(?<domain>[^.]+)\.(?<tld>[^@]+)

# Email with Subdomain
# Pattern: (?<local>[^@]+)@(?<subdomain>[^.]+)\.(?<domain>[^.]+)\.(?<tld>[^.]+)
# Input: user@mail.example.com
# Groups: local=user, subdomain=mail, domain=example, tld=com
(?<local>[^@]+)@(?<subdomain>[^.]+)\.(?<domain>[^.]+)\.(?<tld>[^.]+)

# Email with Plus Tagging
# Pattern: (?<local>[^+]+)\+(?<tag>[^@]+)@(?<domain>[^.]+)\.(?<tld>[^@]+)
# Input: user+promo@example.com
# Groups: local=user, tag=promo, domain=example, tld=com
(?<local>[^+]+)\+(?<tag>[^@]+)@(?<domain>[^.]+)\.(?<tld>[^@]+)

# Country Code TLD
# Pattern: (?<local>[^@]+)@(?<domain>[^.]+)\.(?<tld>[^.]+)\.(?<country>[a-z]{2})
# Input: user@example.co.uk
# Groups: local=user, domain=example, tld=co, country=uk
(?<local>[^@]+)@(?<domain>[^.]+)\.(?<tld>[^.]+)\.(?<country>[a-z]{2})

# Academic Email
# Pattern: (?<local>[^@]+)@(?<department>[^.]+)\.(?<university>[^.]+)\.(?<tld>edu)
# Input: student@cs.mit.edu
# Groups: local=student, department=cs, university=mit, tld=edu
(?<local>[^@]+)@(?<department>[^.]+)\.(?<university>[^.]+)\.(?<tld>edu)
文本regex复杂

日志文件解析模式

解析带有时间戳、级别、消息和元数据的服务器日志条目

难度

7/10

预计时间

12 min

标签

logging, parsing, server, debugging

regex
# Log File Parsing with Named Groups
# Extract timestamp, level, logger, message from log entries

# Apache Common Log Format
# Pattern: (?<ip>\d+\.\d+\.\d+\.\d+) - (?<user>\S+) \[(?<timestamp>[^\]]+)\] "(?<method>\w+) (?<path>\S+) (?<protocol>\S+)" (?<status>\d+) (?<size>\d+)
# Input: 192.168.1.1 - - [16/Jan/2025:14:30:45 +0000] "GET /index.html HTTP/1.1" 200 1234
# Groups: ip=192.168.1.1, user=-, timestamp=16/Jan/2025:14:30:45 +0000, method=GET, path=/index.html, protocol=HTTP/1.1, status=200, size=1234
(?<ip>\d+\.\d+\.\d+\.\d+) - (?<user>\S+) \[(?<timestamp>[^\]]+)\] "(?<method>\w+) (?<path>\S+) (?<protocol>\S+)" (?<status>\d+) (?<size>\d+)

# Application Log Format
# Pattern: \[(?<timestamp>[^\]]+)\] (?<level>\w+) (?<logger>\S+) - (?<message>.*)
# Input: [2025-01-16 14:30:45] INFO com.example.Service - Request processed successfully
# Groups: timestamp=2025-01-16 14:30:45, level=INFO, logger=com.example.Service, message=Request processed successfully
\[(?<timestamp>[^\]]+)\] (?<level>\w+) (?<logger>\S+) - (?<message>.*)

# Error Log with Exception
# Pattern: \[(?<timestamp>[^\]]+)\] (?<level>ERROR) (?<logger>\S+) - (?<message>[^\[]+) \[(?<exception>[^\]]+)\]
# Input: [2025-01-16 14:30:45] ERROR com.example.Service - Database connection failed [SQLException: Connection timeout]
# Groups: timestamp=2025-01-16 14:30:45, level=ERROR, logger=com.example.Service, message=Database connection failed, exception=SQLException: Connection timeout
\[(?<timestamp>[^\]]+)\] (?<level>ERROR) (?<logger>\S+) - (?<message>[^\[]+) \[(?<exception>[^\]]+)\]

# Nginx Log Format
# Pattern: (?<ip>[^ ]*) - (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\w+) (?<path>[^ ]*) (?<protocol>[^"]*)" (?<status>\d+) (?<size>\d+) "(?<referrer>[^"]*)" "(?<ua>[^"]*)"
# Input: 127.0.0.1 - - [16/Jan/2025:14:30:45 +0000] "GET /api/users HTTP/1.1" 200 1234 "-" "Mozilla/5.0"
# Groups: ip=127.0.0.1, user=-, time=16/Jan/2025:14:30:45 +0000, method=GET, path=/api/users, protocol=HTTP/1.1, status=200, size=1234, referrer=-, ua=Mozilla/5.0
(?<ip>[^ ]*) - (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\w+) (?<path>[^ ]*) (?<protocol>[^"]*)" (?<status>\d+) (?<size>\d+) "(?<referrer>[^"]*)" "(?<ua>[^"]*)"
文本regex简单

IP地址解析模式

从IPv4地址中提取IP地址八位字节和组件

难度

4/10

预计时间

6 min

标签

network, ip, parsing, addressing

regex
# IP Address Parsing with Named Groups
# Extract octets from IPv4 addresses

# Standard IPv4
# Pattern: (?<octet1>\d{1,3})\.(?<octet2>\d{1,3})\.(?<octet3>\d{1,3})\.(?<octet4>\d{1,3})
# Input: 192.168.1.1
# Groups: octet1=192, octet2=168, octet3=1, octet4=1
(?<octet1>\d{1,3})\.(?<octet2>\d{1,3})\.(?<octet3>\d{1,3})\.(?<octet4>\d{1,3})

# IP with CIDR Notation
# Pattern: (?<octet1>\d{1,3})\.(?<octet2>\d{1,3})\.(?<octet3>\d{1,3})\.(?<octet4>\d{1,3})/(?<cidr>\d{1,2})
# Input: 192.168.1.0/24
# Groups: octet1=192, octet2=168, octet3=1, octet4=0, cidr=24
(?<octet1>\d{1,3})\.(?<octet2>\d{1,3})\.(?<octet3>\d{1,3})\.(?<octet4>\d{1,3})/(?<cidr>\d{1,2})

# IP with Port
# Pattern: (?<octet1>\d{1,3})\.(?<octet2>\d{1,3})\.(?<octet3>\d{1,3})\.(?<octet4>\d{1,3}):(?<port>\d{1,5})
# Input: 192.168.1.1:8080
# Groups: octet1=192, octet2=168, octet3=1, octet4=1, port=8080
(?<octet1>\d{1,3})\.(?<octet2>\d{1,3})\.(?<octet3>\d{1,3})\.(?<octet4>\d{1,3}):(?<port>\d{1,5})

# Network and Broadcast
# Pattern: (?<network>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/(?<cidr>\d{1,2}) (?:broadcast: (?<broadcast>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))
# Input: 192.168.1.0/24 broadcast: 192.168.1.255
# Groups: network=192.168.1.0, cidr=24, broadcast=192.168.1.255
(?<network>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/(?<cidr>\d{1,2}) (?:broadcast: (?<broadcast>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))
文本regex中等

GPS坐标解析模式

从GPS坐标格式中提取纬度和经度

难度

5/10

预计时间

8 min

标签

gps, coordinates, location, geography

regex
# GPS Coordinates Parsing with Named Groups
# Extract latitude and longitude from coordinate strings

# Decimal Degrees
# Pattern: (?<lat>-?\d+\.\d+),\s*(?<lon>-?\d+\.\d+)
# Input: 40.7128, -74.0060
# Groups: lat=40.7128, lon=-74.0060
(?<lat>-?\d+\.\d+),\s*(?<lon>-?\d+\.\d+)

# DMS Format (Degrees Minutes Seconds)
# Pattern: (?<lat_deg>\d+)°(?<lat_min>\d+)'(?<lat_sec>\d+(?:\.\d+)?)?" (?<lat_dir>[NS]), (?<lon_deg>\d+)°(?<lon_min>\d+)'(?<lon_sec>\d+(?:\.\d+)?)?" (?<lon_dir>[EW])
# Input: 40°42'55" N, 74°00'21" W
# Groups: lat_deg=40, lat_min=42, lat_sec=55, lat_dir=N, lon_deg=74, lon_min=00, lon_sec=21, lon_dir=W
(?<lat_deg>\d+)°(?<lat_min>\d+)'(?<lat_sec>\d+(?:\.\d+)?)?" (?<lat_dir>[NS]), (?<lon_deg>\d+)°(?<lon_min>\d+)'(?<lon_sec>\d+(?:\.\d+)?)?" (?<lon_dir>[EW])

# Degrees Decimal Minutes
# Pattern: (?<lat_deg>\d+)°(?<lat_min>\d+\.\d+)' (?<lat_dir>[NS]), (?<lon_deg>\d+)°(?<lon_min>\d+\.\d+)' (?<lon_dir>[EW])
# Input: 40°42.917' N, 74°00.350' W
# Groups: lat_deg=40, lat_min=42.917, lat_dir=N, lon_deg=74, lon_min=00.350, lon_dir=W
(?<lat_deg>\d+)°(?<lat_min>\d+\.\d+)' (?<lat_dir>[NS]), (?<lon_deg>\d+)°(?<lon_min>\d+\.\d+)' (?<lon_dir>[EW])

# Geo URI Format
# Pattern: geo:(?<lat>-?\d+\.\d+),(?<lon>-?\d+\.\d+)(?:\?z=(?<zoom>\d+))?
# Input: geo:40.7128,-74.0060?z=15
# Groups: lat=40.7128, lon=-74.0060, zoom=15
geo:(?<lat>-?\d+\.\d+),(?<lon>-?\d+\.\d+)(?:\?z=(?<zoom>\d+))?
文本regex中等

产品代码解析模式

从SKU、UPC和产品代码中提取产品信息

难度

6/10

预计时间

10 min

标签

product, sku, inventory, parsing

regex
# Product Code Parsing with Named Groups
# Extract category, SKU, variant from product codes

# Simple SKU
# Pattern: (?<category>[A-Z]{2})-(?<sku>\d{4})-(?<variant>[A-Z]{2})
# Input: EL-1234-LG
# Groups: category=EL, sku=1234, variant=LG
(?<category>[A-Z]{2})-(?<sku>\d{4})-(?<variant>[A-Z]{2})

# UPC-A Barcode
# Pattern: (?<system>\d{1})(?<mfg>\d{5})(?<product>\d{5})(?<check>\d{1})
# Input: 012345678901
# Groups: system=0, mfg=12345, product=67890, check=1
(?<system>\d{1})(?<mfg>\d{5})(?<product>\d{5})(?<check>\d{1})

# ISBN-13
# Pattern: (?<prefix>\d{3})-(?<group>\d{1,5})-(?<publisher>\d{1,7})-(?<title>\d{1,7})-(?<check>\d{1})
# Input: 978-0-306-40615-7
# Groups: prefix=978, group=0, publisher=306, title=40615, check=7
(?<prefix>\d{3})-(?<group>\d{1,5})-(?<publisher>\d{1,7})-(?<title>\d{1,7})-(?<check>\d{1})

# Color-Size Product Code
# Pattern: (?<product>[A-Z]{3})(?<size>XS|S|M|L|XL)(?<color>BL|RD|GR|BK)
# Input: TSHIRTLRDBL
# Groups: product=TSHIRT, size=L, color=RD
(?<product>[A-Z]{3})(?<size>XS|S|M|L|XL)(?<color>BL|RD|GR|BK)

# Hierarchical Product Code
# Pattern: (?<dept>\d{2})\.(?<class>\d{2})\.(?<item>\d{4})-(?<color>\d{2})
# Input: 10.20.1234-56
# Groups: dept=10, class=20, item=1234, color=56
(?<dept>\d{2})\.(?<class>\d{2})\.(?<item>\d{4})-(?<color>\d{2})
文本regex中等

文件路径解析模式

从文件路径中提取目录、文件名和扩展名

难度

5/10

预计时间

8 min

标签

file, path, filesystem, parsing

regex
# File Path Parsing with Named Groups
# Extract directory, filename, extension from file paths

# Unix Path
# Pattern: (?<dir>/[^/]*)/(?<file>[^/]+)\.(?<ext>[^.]+)
# Input: /home/user/documents/report.pdf
# Groups: dir=/home/user/documents, file=report, ext=pdf
(?<dir>/[^/]*)/(?<file>[^/]+)\.(?<ext>[^.]+)

# Windows Path
# Pattern: (?<drive>[A-Z]:)\\(?<dir>[^\\]+)\\(?<file>[^\\]+)\.(?<ext>[^.]+)
# Input: C:\\Users\\Admin\\Documents\\report.docx
# Groups: drive=C:, dir=Users\Admin\Documents, file=report, ext=docx
(?<drive>[A-Z]:)\\(?<dir>[^\\]+)\\(?<file>[^\\]+)\.(?<ext>[^.]+)

# URL Path
# Pattern: https?://[^/]+(?<path>/[^/]+/)(?<file>[^/]+)\.(?<ext>[^.]+)
# Input: https://example.com/downloads/images/photo.jpg
# Groups: path=/downloads/images/, file=photo, ext=jpg
https?://[^/]+(?<path>/[^/]+/)(?<file>[^/]+)\.(?<ext>[^.]+)

# Hidden File (Unix)
# Pattern: (?<dir>/[^/]*)/(?<hidden>\.(?<file>[^/]+))\.(?<ext>[^.]+)
# Input: /home/user/.bashrc.backup
# Groups: dir=/home/user, hidden=.bashrc, file=bashrc, ext=backup
(?<dir>/[^/]*)/(?<hidden>\.(?<file>[^/]+))\.(?<ext>[^.]+)

# Versioned Filename
# Pattern: (?<file>[^-]+)-(?<version>\d+\.\d+\.\d+)\.(?<ext>[^.]+)
# Input: myapp-2.1.0.tar.gz
# Groups: file=myapp, version=2.1.0, ext=tar.gz
(?<file>[^-]+)-(?<version>\d+\.\d+\.\d+)\.(?<ext>[^.]+)
文本regex复杂

人名解析模式

将人名解析为标题、名字、中间名、姓氏和后缀

难度

7/10

预计时间

12 min

标签

name, parsing, personal, formatting

regex
# Person Name Parsing with Named Groups
# Parse names into title, first, middle, last, suffix

# Full Name with Title
# Pattern: (?<title>Mr|Mrs|Ms|Dr|Prof)\.? (?<first>[A-Z][a-z]+) (?<last>[A-Z][a-z]+)
# Input: Dr. John Smith
# Groups: title=Dr, first=John, last=Smith
(?<title>Mr|Mrs|Ms|Dr|Prof)\.? (?<first>[A-Z][a-z]+) (?<last>[A-Z][a-z]+)

# Name with Middle Initial
# Pattern: (?<first>[A-Z][a-z]+) (?<middle>[A-Z])\. (?<last>[A-Z][a-z]+)
# Input: John A. Smith
# Groups: first=John, middle=A, last=Smith
(?<first>[A-Z][a-z]+) (?<middle>[A-Z])\. (?<last>[A-Z][a-z]+)

# Name with Suffix
# Pattern: (?<first>[A-Z][a-z]+) (?<last>[A-Z][a-z]+) (?<suffix>Jr|Sr|II|III|IV)
# Input: Robert Smith Jr
# Groups: first=Robert, last=Smith, suffix=Jr
(?<first>[A-Z][a-z]+) (?<last>[A-Z][a-z]+) (?<suffix>Jr|Sr|II|III|IV)

# Full Name with Middle Name
# Pattern: (?<first>[A-Z][a-z]+) (?<middle>[A-Z][a-z]+) (?<last>[A-Z][a-z]+)
# Input: William Henry Harrison
# Groups: first=William, middle=Henry, last=Harrison
(?<first>[A-Z][a-z]+) (?<middle>[A-Z][a-z]+) (?<last>[A-Z][a-z]+)

# Last, First Format
# Pattern: (?<last>[A-Z][a-z]+), (?<first>[A-Z][a-z]+)(?: (?<middle>[A-Z][a-z]+))?
# Input: Smith, John Henry
# Groups: last=Smith, first=John, middle=Henry
(?<last>[A-Z][a-z]+), (?<first>[A-Z][a-z]+)(?: (?<middle>[A-Z][a-z]+))?
文本regex复杂

信用卡解析模式

从信用卡号中提取卡片组件(BIN、账号、校验位)

难度

8/10

预计时间

10 min

标签

payment, credit card, financial, validation

regex
# Credit Card Parsing with Named Groups
# Extract BIN, account number, and check digit from card numbers

# Visa Card (16 digits)
# Pattern: (?<network>4)(?<bin>\d{4})(?<account>\d{8})(?<check>\d{4})
# Input: 4532015112830366
# Groups: network=4, bin=4532, account=01511283, check=0366
(?<network>4)(?<bin>\d{4})(?<account>\d{8})(?<check>\d{4})

# Mastercard (16 digits)
# Pattern: (?<network>5[1-5])(?<bin>\d{3})(?<account>\d{9})(?<check>\d{3})
# Input: 5555555555554444
# Groups: network=55, bin=555, account=555555555, check=444
(?<network>5[1-5])(?<bin>\d{3})(?<account>\d{9})(?<check>\d{3})

# Amex (15 digits)
# Pattern: (?<network>3[47])(?<bin>\d{4})(?<account>\d{7})(?<check>\d{4})
# Input: 378282246310005
# Groups: network=37, bin=8282, account=2463100, check=0005
(?<network>3[47])(?<bin>\d{4})(?<account>\d{7})(?<check>\d{4})

# Formatted Card Number
# Pattern: (?<network>\d{4})-(?<bin>\d{4})-(?<account>\d{4})-(?<check>\d{4})
# Input: 4532-0151-1283-0366
# Groups: network=4532, bin=0151, account=1283, check=0366
(?<network>\d{4})-(?<bin>\d{4})-(?<account>\d{4})-(?<check>\d{4})

# Card with Expiry and CVV
# Pattern: (?<number>\d{16}) Exp: (?<expiry>\d{2}/\d{2}) CVV: (?<cvv>\d{3,4})
# Input: 4532015112830366 Exp: 12/25 CVV: 123
# Groups: number=4532015112830366, expiry=12/25, cvv=123
(?<number>\d{16}) Exp: (?<expiry>\d{2}/\d{2}) CVV: (?<cvv>\d{3,4})
文本regex中等

语义版本解析模式

将语义版本字符串解析为主要、次要、补丁和预发布组件

难度

6/10

预计时间

10 min

标签

version, semver, parsing, release

regex
# Semantic Version Parsing with Named Groups
# Parse major, minor, patch, pre-release, build from version strings

# Basic SemVer
# Pattern: v?(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)
# Input: v2.1.0
# Groups: major=2, minor=1, patch=0
v?(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)

# SemVer with Pre-release
# Pattern: v?(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<pre>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?
# Input: 2.0.0-alpha.1
# Groups: major=2, minor=0, patch=0, pre=alpha.1
v?(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<pre>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?

# SemVer with Build Metadata
# Pattern: v?(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<pre>[0-9A-Za-z-]+))?(?:\+(?<build>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?
# Input: 1.4.2-beta+exp.sha.5114f85
# Groups: major=1, minor=4, patch=2, pre=beta, build=exp.sha.5114f85
v?(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<pre>[0-9A-Za-z-]+))?(?:\+(?<build>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?

# Package Version
# Pattern: (?<name>[a-z]+)@(?<version>\d+\.\d+\.\d+)
# Input: package@2.1.0
# Groups: name=package, version=2.1.0
(?<name>[a-z]+)@(?<version>\d+\.\d+\.\d+)

# Version Range
# Pattern: (?<min>\d+\.\d+\.\d+) - (?<max>\d+\.\d+\.\d+)
# Input: 1.0.0 - 2.0.0
# Groups: min=1.0.0, max=2.0.0
(?<min>\d+\.\d+\.\d+) - (?<max>\d+\.\d+\.\d+)

工具

经常与该案例搭配使用的工具

相关内容

相关案例集合

相关内容

相关专题

专题

Excel 工作簿的专业化装配

把裸表格装配成别人无需提问就能使用的工作簿——升级旧格式文件、公式批量下填并锁定公式单元格、命名区域、用验证下拉把守输入端、让条件格式替你标出异常、冻结表头、生成目录页,并把打印设置一次做齐。

专题

正则测试、可视化与安全审查工作流

通过语法参考、匹配测试、结构可视化、替换预览、性能对比和 ReDoS 扫描,构建更可靠的正则表达式。

专题

JSON 结构手术

带着记录对 JSON 结构动刀——动手前先盘点全部键路径,用 RFC 6901 指针精确寻址或用 JSONPath 灵活选集,按规则而非手工重命名键,以 RFC 6902 补丁施加可审计的操作序列,需要出门时扁平化、回来时无损还原。

专题

音频库批量清理与交付

把一堆混杂的音频文件整理成可交付的音频库——查找并裁决重复文件、整批转为统一格式并有意设置编码参数、钉死 CBR 或 VBR 码率策略、批量修复标签与文件名、变速不变调地校正播放速度。

首页
工具3212
案例593
可视化471
文件查看器103
专题239
标签333
图像、音频与视频657

图像、音频、视频处理、转换与优化工具

数学、日期与金融647

计算器、数值计算、日期逻辑、统计与金融工具

设计与颜色298

颜色、版式、图形、视觉样式与设计辅助工具

文本与写作209

写作、清洗、格式化、提取与文本分析工具

开发与 Web193

开发者工具、网络处理、Web 调试与自动化辅助工具

转换与编码175

格式、文件、压缩包、单位与编码转换工具

潜客测验发布与联系人交接
讣告、悼词与纪念卡的家属复核及交付
本地习惯记录的备份、恢复演练与分享前检查
长文改编 X 串文与 LinkedIn 帖子的事实复核与交付
Markdown 互动课件审校、离线演示与交付

© 2026 Elysia Tools. 保留所有权利。

文档价格关于我们服务条款隐私政策Cookie 政策联系我们

Media

音频剪切工具

从音频文件中剪切和提取音频片段,支持精确的时间选择

Media

DTMF 解码器

从任意录音中检测 DTMF 按键音并还原按键序列与时间戳。按 ITU-T Q.23/Q.24 用 Goertzel 滤波器组实现——逐键测量两个频率、扭曲与时长。

Media

音频旋律轮廓提取器

从音频中提取主导旋律,并在一个 ZIP 中导出 MIDI、音符事件、音高轮廓、SVG 和 JSON。

Media

音频混合器

混合两个音频文件,支持自定义时间控制

Media

音频底噪时间线

按时间追踪启发式低电平 RMS 代理值,单独统计数字静音并逐声道标记变化。

Media

音频差分抵消测试

直接逐采样相减比较两个音频文件,导出残差和测量报告。

Media

音频变速器

改变音频播放速度,同时保持原始音调,使用时间拉伸算法

Media

FFmpeg音频降噪工具

使用FFmpeg高级滤波器(高通、afftdn、loudnorm)进行专业音频降噪,获得最佳音频清洁效果

C#

Windows Web端功能 - C# 示例

Windows平台C# Web端功能示例,包括路由处理、中间件和静态文件服务

DevOps

ELK Stack 日志分析示例

全面的 ELK Stack(Elasticsearch、Logstash、Kibana)示例,用于分布式系统中的日志聚合、处理和可视化

数据格式

环境变量(.env)示例

不同应用程序类型和环境的环境变量配置示例

Objective-C

macOS Objective-C Web端功能示例

macOS Objective-C Web端功能示例,包括URL路由、中间件和静态文件服务

C#

Windows 错误处理 - C# 示例

Windows平台C#错误处理示例,包括异常处理、日志记录和参数验证

C++

Windows C++ Web功能示例

Windows C++ Web服务器开发示例,包括URL路由、中间件和静态文件服务