-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from saade/feat/to-have-title-regex
feat: support both regex and non regex titles
- Loading branch information
Showing
3 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pest\Browser\Support; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class Str | ||
{ | ||
/** | ||
* Check if the given string is a regex. | ||
*/ | ||
public static function isRegex(string $target): bool | ||
{ | ||
if (strlen($target) < 2) { | ||
return false; | ||
} | ||
|
||
// If the first and last characters are not the same, it's not a regex | ||
if (($delimiter = substr($target, 0, 1)) !== substr($target, -1, 1)) { | ||
return false; | ||
} | ||
|
||
// If the delimiter is alphanumeric, it's not a regex | ||
if (! preg_match('/[^a-zA-Z0-9]/', $delimiter)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters