Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

GTS-MEG's avatar

preg_match(): No ending delimiter '#'

As the title said, I have this rule

 'stock.colorEntries.*.color.hexCode' => ['required', 'string', 'distinct',
                'regex:#^([0-9A-F]{3}|[0-9A-F]{6}|[0-9A-F]{8})$#']

I get this error :

ErrorException: preg_match(): No ending delimiter '#' found in file

My validations rules are already in array format, no pipes at all, even this error still occurs

The weird thing is when I assign the same rule to a non wrapped attribute in my request form, this error doesn't occurs. Maybe it's a bug when using regex for nested attributes

Github : https://github.com/laravel/framework/issues/41023

0 likes
9 replies
GTS-MEG's avatar

I do believe this is a bug I Ihave this piece of code

 public function rules(): array
    {
        return [
          /* 'stock.colorEntries.*.color.hexCode' => ['required', 'string', 'distinct',
                'regex:'.GlobalRegex::COLOR_HEX_CODE_PATTERN],*/
            'a' => ['required', 'string', 'distinct',
                'regex:'.GlobalRegex::COLOR_HEX_CODE_PATTERN],
        ];
}

This code seems to work, but when I uncomment 'stock.colorEntries.*.color.hexCode attribute, I get the error again

Sinnbeck's avatar

@GTS-MEG Can you make a simple example of how to recreate it? Or make a repo on github where we can see it? As I understand you, it only breaks in very specific circumstances?

GTS-MEG's avatar

@Sinnbeck It breaks when I apply the regular expression rule on nested attributes as I posted the sample code

GTS-MEG's avatar

@sinnbeck Replication : Having the following payload as a json format :


{
	"a":"123456",
	"b" : {
		"c" : [{
			"d": {
				"test": "123456"
			}
		}]
	}
}

Having this FormRequest to validate the payload :

    public function rules(): array
    {
        return [
           'b.c.*.d.test' => ['required', 'string', 'distinct',
                'regex:'.GlobalRegex::COLOR_HEX_CODE_PATTERN],
            'a' => ['required', 'string', 'distinct',
                'regex:'.GlobalRegex::COLOR_HEX_CODE_PATTERN],
        ];
    }
    const COLOR_HEX_CODE_PATTERN = '#^([0-9A-F]{3}|[0-9A-F]{6}|[0-9A-F]{8})$#';

This error occurs when validating the test attribute

Please or to participate in this conversation.