File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 44
55class StringProcessor
66{
7+ /**
8+ * Matches a pattern to a fuzzy subject, e.g. 'api.*' should match 'api.enabled'
9+ *
10+ * @param string $pattern The pattern that the subject should match, e.g. 'api.*'
11+ * @param string $subject The subject that is being compared, e.g. 'api.enabled'
12+ * @return boolean Whether the string matches.
13+ */
14+ public static function fuzzyMatch (string $ pattern , string $ subject ): bool
15+ {
16+ $ pattern = \preg_replace_callback ('/([^*])/ ' , 'preg_quote ' , $ pattern );
17+ $ pattern = \str_replace ('* ' , '.* ' , $ pattern );
18+ return (bool ) \preg_match ('/^ ' . $ pattern . '$/i ' , $ subject );
19+ }
20+
721 /**
822 * Checks whether the current User Agent is a GUI web browser known by a common string, e.g. Firefox.
923 *
You can’t perform that action at this time.
0 commit comments