← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

ereg() / eregi() — POSIX Regex Removed in PHP 7

php PHP 3.0+ Beginner

TL;DR

ereg() and eregi() were POSIX regex functions removed in PHP 7.0 — replace with preg_match() (PCRE) which is faster, more powerful, and the standard since PHP 4.

Explanation

ereg() and eregi() (case-insensitive) used POSIX Extended Regular Expressions. Deprecated in PHP 5.3, removed in PHP 7.0. PCRE (Perl-Compatible Regular Expressions) via preg_match() is faster and far more capable. Migration: ereg('pattern', $string, $matches) → preg_match('/pattern/', $string, $matches). Delimiters required in preg_match. eregi → preg_match with /i flag. ereg_replace → preg_replace. split → preg_split. Rector handles this migration automatically.

Common Misconception

ereg() is just an older alias for preg_match() — they use different regex flavours (POSIX vs PCRE) and have different syntax and capabilities.

Why It Matters

The ereg family (ereg, eregi, ereg_replace, eregi_replace, split, spliti) was removed in PHP 7. Any codebase still using these functions throws fatal errors immediately on upgrade. They are slower than PCRE, lack Unicode support, and the case-insensitive variants use locale-dependent comparison which produces inconsistent results across server environments. Migrating to preg_* is a direct mechanical replacement in most cases.

Common Mistakes

  • Not running Rector to auto-migrate ereg to preg_match.
  • Direct translation missing delimiters: ereg('foo') → preg_match('foo') — wrong, needs /foo/.
  • Forgetting eregi → preg_match with /i flag.

Code Examples

✗ Vulnerable
if (ereg('^[a-z]+$', $input)) { } // Fatal in PHP 7+
eregi('[0-9]', $string); // Case-insensitive digit check
✓ Fixed
if (preg_match('/^[a-z]+$/i', $input)) { } // PCRE
if (preg_match('/[0-9]/', $string)) { } // Digits

Added 23 Mar 2026
Views 43
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W 2 pings T 2 pings F 3 pings S 2 pings S 3 pings M 1 ping T 0 pings W 0 pings T 1 ping F 0 pings S
No pings yet today
ChatGPT 18 Amazonbot 6 Google 6 Unknown AI 3 Perplexity 3 Ahrefs 1
crawler 34 crawler_json 1 pre-tracking 2
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Low
⚡ Quick Fix
Run Rector migration rules to auto-convert ereg/eregi to preg_match. Add /delimiters/ and /i flag for case-insensitivity.
📦 Applies To
PHP 3.0+ web cli
🔗 Prerequisites
🔍 Detection Hints
ereg\(|eregi\(|ereg_replace\(|split\(
Auto-detectable: ✓ Yes rector phpcs
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Low Context: Line Tests: Update

✓ schema.org compliant