Skip to content

Commit

Permalink
Put - at end of character class in regex
Browse files Browse the repository at this point in the history
This avoids the need to escape the dash in character classes.
  • Loading branch information
biochimia committed Jan 4, 2024
1 parent 8f72201 commit 6f6ac3e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Parser/AbstractParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ protected function matchUserAgent(string $regex): ?array
$matches = [];

// only match if useragent begins with given regex or there is no letter before it
$regex = '/(?:^|[^A-Z0-9\-_]|[^A-Z0-9\-]_|sprd-|MZ-)(?:' . \str_replace('/', '\/', $regex) . ')/i';
$regex = '/(?:^|[^A-Z0-9_-]|[^A-Z0-9-]_|sprd-|MZ-)(?:' . \str_replace('/', '\/', $regex) . ')/i';

try {
if (\preg_match($regex, $this->userAgent, $matches)) {
Expand Down
2 changes: 1 addition & 1 deletion regexes/bots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3533,5 +3533,5 @@
url: 'https://www.bbc.com/'

# Generic detections
- regex: '[a-z0-9\-_]*(?:(?<!cu|power[ _]|m[ _])bot(?![ _]TAB|[ _]?5[0-9]|[ _]Senior|[ _]Junior)|crawler|crawl|checker|archiver|transcoder|spider|^firefox$|^chrome$)(?:[^a-z]|$)'
- regex: '[a-z0-9_-]*(?:(?<!cu|power[ _]|m[ _])bot(?![ _]TAB|[ _]?5[0-9]|[ _]Senior|[ _]Junior)|crawler|crawl|checker|archiver|transcoder|spider|^firefox$|^chrome$)(?:[^a-z]|$)'
name: 'Generic Bot'

0 comments on commit 6f6ac3e

Please # to comment.