🌐
W3Schools
w3schools.com › php › php_regex.asp
PHP Regular Expressions
Superglobals $GLOBALS $_SERVER $_REQUEST $_POST $_GET PHP RegEx PHP RegEx Functions
🌐
Regex101
regex101.com
regex101: build, test, and debug regex
Online regex tester and debugger with real-time match highlighting, detailed explanations, substitutions, unit tests, benchmarking, and code generation. Supports PCRE2, JavaScript, Python, Go, Java, .NET, Rust, POSIX ERE, and POSIX BRE.
Discussions

Regular expression pattern works on regex101.com but not in php CLI
Honestly I would't use regex for this. I would write a script that parses the file line by line and check if a line starts with a timestamp. Then use a smaller simpler regex to extract the timestamps and you can parse the next few lines that contain the text in total until you encounter a new timestamp or number block. More on reddit.com
🌐 r/PHPhelp
7
4
January 15, 2023
Easy work with regex groups;
That sort of reminds me of applicative parser combinators, although less composable. There are few parser combinator libraries for PHP but they aim for fully monadic parsers, which will probably never reach the performance of an optimized regular expression engine. I wonder if we could make a library with nice composable interface that would build a single regular expression in the background (imagining something like Nikita Popov’s FastRoute ), followed by a thin hydration layer. For example how this can be achieved in other languages, in Haskell, I can define a data structure and then “regular expression objects” (RE parsers) that will produce the final datastructure with the help of smaller parsers: import Text.Regex.Applicative data TinWoodman = TinWoodman { head :: String, arms :: String, legs :: String, body :: String, heart :: Maybe String } deriving (Show) anyStringRegex :: RE Char String anyStringRegex = many anySym tinWoodmanRegex :: RE Char TinWoodman tinWoodmanRegex = TinWoodman <$> (anyStringRegex *> string "head") <*> (anyStringRegex *> string "arms") <*> (anyStringRegex *> string "legs") <*> (anyStringRegex *> string "body") <*> (optional (anyStringRegex *> string "heart")) <* anyStringRegex In the example above, something like the following happens: string function creates a “regex object” that accepts the string given to it and also returns it as the result. anyStringRegex is .*. <*> and <$> help to pass the results of parser on the right hand side to the TinWoodman constructor function. optional function takes a parser and returns a new parser that will return the result of the inner parser wrapped in Just, or Nothing if the inner parser does not match. *> runs the parser on the left hand side, discards its result, and then runs the parser on the right and returns its result. The parser can be executed as follows: ghci> match tinWoodmanRegex "One of the big trees had been partly chopped through, and standing beside it, with an uplifted axe in his hands, was a man made entirely of tin. His head and arms and legs were jointed upon his body, but he stood perfectly motionless, as if he could not stir at all." Just (TinWoodman {head = "head", arms = "arms", legs = "legs", body = "body", heart = Nothing}) More on reddit.com
🌐 r/PHP
2
0
July 14, 2023
[PHP] I made regex on regex101.com, but it doesnt work in my code.
Click on the Code Generator button https://regex101.com/r/8xZ0a5/1/codegen?language=php The issue is the number of backslashes in your pattern. Because it's quoted (a "string") you need \\ to match a single \ - so you need 4 in your pattern not 2. More on reddit.com
🌐 r/learnprogramming
8
1
February 17, 2017
Online regex tester and debugger: JavaScript, Python, PHP, and PCRE
I was ready to recommend Regexr over this, the explanation panels are actually really cool and useful. More on reddit.com
🌐 r/PHP
18
73
January 22, 2015
🌐
Medium
roman-huliak.medium.com › using-regular-expressions-in-php-a-practical-guide-a26a6cc8232e
Using regular expressions in PHP: A practical guide | by Roman Huliak | Medium
May 22, 2025 - PHP provides two main sets of functions for working with regular expressions: POSIX-style regex functions (deprecated): ereg(), eregi(), etc.
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-regular-expressions
PHP | Regular Expressions - GeeksforGeeks
July 12, 2025 - The exact sequence of characters are unpredictable beforehand, so the regex helps in fetching the required strings based on a pattern definition. Regular Expression is a compact way of describing a string pattern that matches a particular amount of text. As you know, PHP is an open-source language commonly used for website creation, it provides regular expression functions as an important tool.
🌐
Phpliveregex
phpliveregex.com
PHP Live Regex
i case insensitive m treat as multi-line string s dot matches newline x ignore whitespace in regex A matches only at the start of string D matches only at the end of string U non-greedy matching by default
🌐
Rexegg
rexegg.com › regex-php.php
PHP Regex Tutorial
Hit Ctrl + F to search for "preg_regex_to_pattern", "preg_pattern_error" and "preg_regex_error". If your version of PHP is 5.2.4 or later (phpinfo is your friend), you can use a wonderful PCRE escape sequence: \K. In the middle of a pattern, \K says "reset the beginning of the reported match to this point". Anything that was matched before the \K goes unreported, a bit like in a lookbehind. For example, on the string "Marlon Brando", the pattern (?i)marlon \Kbrando will return "Brando".
🌐
regex101
regex101.com › library › hkvPij
regex101: PHP
This regex should extract the subdomain, if any, or the domain, if no subdomain is used, from an arbitrary URLSubmitted by trevi@twanda.com ... Find and extract email domain. Ex: test@example.pt -> extract 'example.pt'Submitted by Fnxk
🌐
Regex101
regex101.com › r › qP1rP4 › 1
regex101: PHP identifier
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.
Find elsewhere
🌐
RegExr
regexr.com
RegExr: Learn, Build, & Test RegEx
Regular expression tester with syntax highlighting, PHP / PCRE & JS Support, contextual help, cheat sheet, reference, and searchable community patterns.
🌐
Reddit
reddit.com › r/phphelp › regular expression pattern works on regex101.com but not in php cli
r/PHPhelp on Reddit: Regular expression pattern works on regex101.com but not in php CLI
January 15, 2023 -

Im trying to extract subtitle entries out of a SRT file. Ive written a script that opens the file and with the help of regex fetches the strings. Ive testes the regex pattern on regex101.com using the correct php engine. And it works. For some reason php CLI has an issue with the pattern. It seems that newlines "\n" in the pattern is either causing the problem or the imported file strips all newlines.

here is the regex pattern

^(?<NR>\d+)\n(?<START>\d\d:\d\d:\d\d,\d\d\d)(?>\s?-->\s?)(?<END>\d\d:\d\d:\d\d,\d\d\d)\n(?<STRING>(?>.+\n?)+)

Dummy text:

1
00:00:46,296 --> 00:00:50,425
They were startled and frightened,
thinking they saw a ghost.

2
00:00:50,467 --> 00:00:52,386
He said to them,

3
00:00:54,179 --> 00:00:57,140
"Why are you troubled, and
why do doubts rise in your minds?

4
00:00:57,182 --> 00:00:59,977
<i>Look at my hands and my feet.
It is I myself!</i>

PHP code

<?php
$path1 = $argv[1];
$file1_content = file_get_contents($path1);

$pattern = '%^(?<NR>\d+)\n(?<START>\d\d:\d\d:\d\d,\d\d\d)(?>\s?-->\s?)(?<END>\d\d:\d\d:\d\d,\d\d\d)\n(?<STRING>(?>.+\n?)+)%';
$success = preg_match_all($pattern, $file1_content, $matches);
var_dump($matches);

CLI Instructions

  1. open a text file and save the dummy content into it.

  2. Open your shell and goto dir of txt file.

  3. type %php -f [php-script-file] -- [full-path-to-dummy-file]

🌐
PHP
php.net › manual › en › regexp.introduction.php
PHP: Introduction - Manual
Most characters stand for themselves in a pattern, and match the corresponding characters in the subject. As a trivial example, the pattern The quick brown fox matches a portion of a subject string that is identical to itself.
🌐
Regex101
regex101.com › r › 5VyM27 › 1
regex101: PHP preg_match
An explanation of your regex will be automatically generated as you type.
🌐
Tutorial Republic
tutorialrepublic.com › php-tutorial › php-regular-expressions.php
Regular Expressions in PHP - Tutorial Republic
<?php $pattern = "/^color/im"; $text = "Color red is more visible than \ncolor blue in daylight."; $matches = preg_match_all($pattern, $text, $array); echo $matches . " matches were found."; ?> A word boundary character ( \b) helps you search for the words that begins and/or ends with a pattern. For example, the regexp /\bcar/ matches the words beginning with the pattern car, and would match cart, carrot, or cartoon, but would not match oscar.
🌐
ZetCode
zetcode.com › php › regex
Regular expressions in PHP
January 10, 2023 - $ php extract_matches.php The 10:10:22 is split into: Hour: 10 Minute: 10 Second: 22 The 23:23:11 is split into: Hour: 23 Minute: 23 Second: 11 The 09:06:56 is split into: Hour: 09 Minute: 06 Second: 56 · Next have a practical example. We create a regex pattern for checking email addresses.
🌐
Amir Kamizi
amirkamizi.com › blog › php-regular-expressions
PHP Regular Expressions | Amir Kamizi
March 22, 2023 - Today we are going to learn about regular expressions in PHP. A regular expression is a sequence of characters that specifies a search pattern. it's important to know how to apply them in PHP.
🌐
Regex101
regex101.com › r › bB9kC2 › 1
regex101: recognize php
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.
🌐
Medium
medium.com › @TechnologyDiaries › php-regular-expressions-regex-a-complete-beginners-guide-8fc93cf2c68a
PHP Regular Expressions (Regex): A Complete Beginner’s Guide | by Technology Diaries | Medium
August 18, 2025 - Whether you’re validating user input, searching for specific patterns, or replacing text, regex can make your code more efficient and robust. Regular expressions are sequences of characters that define search patterns. Think of them as a sophisticated “find and replace” tool that can handle complex text operations with just a few lines of code. In PHP, regex is primarily used through PCRE (Perl Compatible Regular Expressions) functions like preg_match(), preg_replace(), and preg_split().
🌐
Jotform
jotform.com › blog › advice › getting started with php regular expressions
Getting Started with PHP Regular Expressions | Jotform Blog
June 25, 2024 - ... Hey Lemon, I think the following may work for you <?php $pattern = '/C.*T/'; $string = "A cat tear a coat"; if (preg_match($pattern, $string)) { echo "Valid String"; }else{ echo "Invalid String"; } ?>
🌐
Tutorialspoint
tutorialspoint.com › php › php_regular_expression.htm
PHP - Regular Expressions
Regular expressions are nothing more than a sequence or pattern of characters itself. They provide the foundation for pattern-matching functionality. Using regular expression you can search a particular string inside a another string, you can