Laravel preg_match(): No ending delimiter '/' found
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Laravel is an amazing framework for building web applications, offering a variety of useful tools to streamline the development process and ensure code quality. However, sometimes, even with its impressive features, we can encounter errors or issues that may seem complex at first glance. One such error is related to Laravel's preg_match() function, which throws an exception stating "preg_match(): No ending delimiter '/' found." This post will walk you through what this error means and how to fix it in your Laravel application.
To begin with, understanding the problem is vital. The Laravel validation library uses preg_match() function under the hood to check for specific patterns against user-provided values. As per the error message, the ending delimiter '/' is missing. This causes an issue as the regex pattern that you provided doesn't have a clear end to it, making it impossible for Laravel to validate your input correctly.
Let us look at how this happens in practice. Suppose we want to ensure that only valid class subjects are entered into our system, such as "Math" or "Physics." We can use the preg_match() function and include a regular expression to check for valid classes. Here's an example using Laravel 4.2:
public static $rules_save = [
'class_subjects' => 'required|regex:/[0-9]([0-9]|-(?!-))+/'
];
The issue occurs when calling this rule to validate a name field with the regex pattern mentioned above. This leads to the error being thrown as Laravel cannot find the closing '/' delimiter within your provided pattern. To resolve this, it is crucial that you carefully review your regular expression and ensure its structure is correct.
In this case, to fix the problem, we need to close our regex pattern with a single backslash-slash (\\/) as shown below:
public static $rules_save = [
'class_subjects' => 'required|regex:/[0-9]([0-9]|-(?!-))+/\/'
];
Remember that the additional backslash character is required to escape the forward slash '/', as it can have multiple uses in regex and can be interpreted differently. This ensures that your pattern now has a clear ending, and Laravel won't have any problem validating the input provided.
To summarize, this blog post aims to provide an understanding of the issue when encountering the "preg_match(): No ending delimiter '/' found" error in Laravel. By going through a real-life example and providing a step-by-step solution, we can overcome this error and ensure our validation rules work as expected.
For further learning on Laravel and regular expressions, check out Laravel Company's blog, which is rich in resources and tutorials for developers working with the framework. Additionally, feel free to reach out to our experts at Laravel Company if you need assistance or have any questions regarding your Laravel projects.