RepositoryPHPBEBelgium
SP

spatie/regex

A sane interface for php's built in preg_* functions

1.1kstars
49forks
0issues
0views

Thành tựu nổi bật

Những danh hiệu mới nhất của dự án

1
TINIX TRENDING·Chủ đề: regular-expression

#1 Repository Của Tháng

2
TINIX TRENDING·Chủ đề: regex

#2 Repository Của Tháng

9
TINIX TRENDING·Quốc gia: BE

#9 Repository Của Tháng

🧼 Regex sạch: preg_* dễ thở hơn với spatie/regex

Giao diện PHP gọn gàng cho preg_match, preg_match_all và preg_replace — không còn biến tham chiếu hay null/false lẫn nhau.

spatie/regex của Spatie (agency thiết kế web tại Brussels, Belgium) là lớp bọc nhẹ giúp làm việc với regex trong PHP trở nên trực quan hơn. Thay vì nhớ cú pháp lẳng lơ của preg_*, bạn nhận được đối tượng MatchResult hỗ trợ kiểu trả về nhất quán.

✨ Điểm nổi bật

  • MatchResult: trả về đối tượng thay vì string|null, hỗ trợ hasMatch(), result(), group(n)
  • resultOr() / groupOr(): thiết lập giá trị mặc định khi không có kết quả
  • matchAll(): trả về danh sách MatchResult cho mọi kết quả khớp
  • replace() hỗ trợ callable: nhận MatchResult như tham số, linh hoạt xử lý thay thế
  • Xử lý lỗi bằng RegexFailed exception: không cần gọi preg_last_error()
  • Hỗ trợ mảng: pattern, replacement, subject đều chấp nhận mảng như preg_replace

💡 Vì sao đáng chú ý

Thư viện nhỏ gọn nhưng giải quyết đúng nỗi đau thực tế: preg_match trả về false khi lỗi, null khi không khớp, và ép dùng biến tham chiếu để lấy nhóm. spatie/regex đóng gói lại thành API nhất quán, an toàn kiểu và dễ đọc — phù hợp cho bất kỳ dự án PHP nào dùng regex thường xuyên.


#PHP #Regex #Spatie #OpenSource #TiniX

Similar Projects

Discover other similar projects and AI models.

RepositoryPHP
gherkins/regexpbuilderphp

🦉 human-readable regular expressions

1.3k
Dec 19, 2025
RepositoryRust
sharkdp/fd

A simple, fast and user-friendly alternative to 'find'

44.9k
Oct 24, 2026
RepositoryRust
pemistahl/grex

A command-line tool and Rust library with Python bindings for generating regular expressions from user-provided test cases

8.3k
Feb 27, 2026
RepositoryRust
yoav-lavi/melody

Melody is a language that compiles to regular expressions and aims to be more readable and maintainable

4.7k
Nov 24, 2024
RepositoryTypeScript
unjs/magic-regexp

A compiled-away, type-safe, readable RegExp alternative

4.3k
Oct 27, 2026
RepositoryJavaScript
mathiasbynens/emoji-regex

A regular expression to match all Emoji-only symbols as per the Unicode Standard.

1.9k
Sep 15, 2026
RepositoryC
PCRE2Project/pcre2

PCRE2 is a library implementing regular expression pattern matching with a C API

1.4k
Oct 23, 2026
RepositoryGo
dlclark/regexp2

A full-featured regex engine in pure Go based on the .NET engine

1.2k
Oct 28, 2026
RepositoryTypeScript
ota-meshi/eslint-plugin-regexp

ESLint plugin for finding regex mistakes and style guide violations.

782
Oct 29, 2026