Repository: laravel/framework (php)

Issue:
Method explodeExplicitRule working wrong with regex rule
<!-- DO NOT THROW THIS AWAY -->
<!-- Fill out the FULL versions with patch versions -->

- Laravel Version: 9.45.1
- PHP Version: 8.1.13
- Database Driver & Version:

### Description:

Method explodeExplicitRule works wrong with this rule `regex:/^[\d\-]*$/|max:20`.

It can not explodes this rule to two patterns like 
```
[
   0 => 'regex:/^[\d\-]*$/',
   1 => 'max:20'
]
```

I have verified it in Laravel 8 and It has worked perfectly.
I saw Laravel 9 had changed explodeExplicitRule which made it wrong.
In another rule like `required|regex:/^[\d\-]*$/|max:20` or just rotate it like `max:20|regex:/^[\d\-]*$/`,
It works perfectly.

https://github.com/laravel/framework/blob/9.x/src/Illuminate/Validation/ValidationRuleParser.php#L86-L103

https://github.com/laravel/framework/blob/8.x/src/Illuminate/Validation/ValidationRuleParser.php#L84-L93

### Steps To Reproduce:

use Laravel validator with rule `regex:/^[\d\-]*$/|max:20`

<!-- If possible, please provide a GitHub repository to demonstrate your issue -->
<!-- laravel new bug-report --github="--public" -->


Pull request description:
[9.x] Method explodeExplicitRule working wrong with regex rule - Issue 45520
Closes #45520 

This PR reverts a change that I made in PR #40941 ([specifically this change](https://github.com/laravel/framework/pull/40941/files#diff-88815c1c8302eb7f025ae9ba1f232036adbfae6a415d3d84d199ad2f3af15c31L88)), which attempted to handle regex rules containing pipes, if they were the only rule in the string. This didn't work as intended when a string rule contains a regex with subsequent rules (as displayed in PR #45520).

This revert returns the validator to its default and documented behaviour of requiring regex rules containing pipes be split into an array of rule strings.

I have also adjusted the tests to ensure this default behaviour is kept, and that we will be notified of such a change due to test failure.

Let me know if you would like anything adjusted, thanks for your time!

Patch:
diff --git a/src/Illuminate/Validation/ValidationRuleParser.php b/src/Illuminate/Validation/ValidationRuleParser.php
index eed342bd82..f34d0a748d 100644
--- a/src/Illuminate/Validation/ValidationRuleParser.php
+++ b/src/Illuminate/Validation/ValidationRuleParser.php
@@ -86,9 +86,7 @@ protected function explodeRules($rules)
     protected function explodeExplicitRule($rule, $attribute)
     {
         if (is_string($rule)) {
-            [$name] = static::parseStringRule($rule);
-
-            return static::ruleIsRegex($name) ? [$rule] : explode('|', $rule);
+            return explode('|', $rule);
         }
 
         if (is_object($rule)) {


Test patch:
diff --git a/tests/Validation/ValidationForEachTest.php b/tests/Validation/ValidationForEachTest.php
index c836844680..1c7bdadfd8 100644
--- a/tests/Validation/ValidationForEachTest.php
+++ b/tests/Validation/ValidationForEachTest.php
@@ -211,7 +211,7 @@ public function testForEachCallbacksDoNotBreakRegexRules()
 
         $rules = [
             'items.*' => Rule::forEach(function () {
-                return ['users.*.type' => 'regex:/^(super|admin)$/i'];
+                return ['users.*.type' => 'regex:/^(super)$/i'];
             }),
         ];
 
diff --git a/tests/Validation/ValidationRuleParserTest.php b/tests/Validation/ValidationRuleParserTest.php
index b40e4375d6..db4ef31c04 100644
--- a/tests/Validation/ValidationRuleParserTest.php
+++ b/tests/Validation/ValidationRuleParserTest.php
@@ -96,7 +96,7 @@ public function testEmptyConditionalRulesArePreserved()
         ], $rules);
     }
 
-    public function testExplodeProperlyParsesSingleRegexRule()
+    public function testExplodeFailsParsingSingleRegexRuleContainingPipe()
     {
         $data = ['items' => [['type' => 'foo']]];
 
@@ -104,7 +104,20 @@ public function testExplodeProperlyParsesSingleRegexRule()
             ['items.*.type' => 'regex:/^(foo|bar)$/i']
         );
 
-        $this->assertSame('regex:/^(foo|bar)$/i', $exploded->rules['items.0.type'][0]);
+        $this->assertSame('regex:/^(foo', $exploded->rules['items.0.type'][0]);
+        $this->assertSame('bar)$/i', $exploded->rules['items.0.type'][1]);
+    }
+
+    public function testExplodeProperlyParsesSingleRegexRuleNotContainingPipe()
+    {
+        $data = ['items' => [['type' => 'foo']]];
+
+        $exploded = (new ValidationRuleParser($data))->explode(
+            ['items.*.type' => 'regex:/^[\d\-]*$/|max:20']
+        );
+
+        $this->assertSame('regex:/^[\d\-]*$/', $exploded->rules['items.0.type'][0]);
+        $this->assertSame('max:20', $exploded->rules['items.0.type'][1]);
     }
 
     public function testExplodeProperlyParsesRegexWithArrayOfRules()