File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -610,6 +610,32 @@ public static function match($pattern, $subject)
610
610
return $ matches [1 ] ?? $ matches [0 ];
611
611
}
612
612
613
+ /**
614
+ * Determine if a given string matches a given pattern.
615
+ *
616
+ * @param string|iterable<string> $pattern
617
+ * @param string $value
618
+ * @return bool
619
+ */
620
+ public static function isMatch ($ pattern , $ value )
621
+ {
622
+ $ value = (string ) $ value ;
623
+
624
+ if (! is_iterable ($ pattern )) {
625
+ $ pattern = [$ pattern ];
626
+ }
627
+
628
+ foreach ($ pattern as $ pattern ) {
629
+ $ pattern = (string ) $ pattern ;
630
+
631
+ if (preg_match ($ pattern , $ value ) === 1 ) {
632
+ return true ;
633
+ }
634
+ }
635
+
636
+ return false ;
637
+ }
638
+
613
639
/**
614
640
* Get the string matching the given pattern.
615
641
*
Original file line number Diff line number Diff line change @@ -440,6 +440,17 @@ public function match($pattern)
440
440
return new static (Str::match ($ pattern , $ this ->value ));
441
441
}
442
442
443
+ /**
444
+ * Determine if a given string matches a given pattern.
445
+ *
446
+ * @param string|iterable<string> $pattern
447
+ * @return bool
448
+ */
449
+ public function isMatch ($ pattern )
450
+ {
451
+ return Str::isMatch ($ pattern , $ this ->value );
452
+ }
453
+
443
454
/**
444
455
* Get the string matching the given pattern.
445
456
*
You can’t perform that action at this time.
0 commit comments