It seems like you're trying to match a number that comes after "p/" and before either the end of the line or the start of the query string "?variant=". The issue you're facing might be related to how newlines are represented in Windows (\r\n) versus Unix-like systems (\n).
You can modify your regular expression to account for both types of line endings. Here's a regex pattern that should work for you:
@(?<=p/)(\d+)(?=\?variant=\d*|[\r\n]|$)@
This pattern uses a positive lookbehind (?<=p/) to ensure that the digits are preceded by "p/". It then captures one or more digits (\d+). Finally, it uses a positive lookahead (?=\?variant=\d*|[\r\n]|$) to assert that what follows is either the start of the query string ?variant=, a newline character (either \r\n for Windows or \n for Unix-like systems), or the end of the string $.
Here's how you can use this pattern in PHP with preg_match:
$urls = "http://xxxxx/p/3001002990
http://xxxxx/p/3001002990?variant=803713";
$pattern = '@(?<=p/)(\d+)(?=\?variant=\d*|[\r\n]|$)@';
preg_match_all($pattern, $urls, $matches);
print_r($matches[0]);
This code will print out all the matches found in the $urls string. The preg_match_all function is used here to find all matches, and $matches[0] will contain the array of numbers that were matched.
Remember that when testing regex patterns on different platforms, line endings can cause issues, so it's always good to account for both \r\n and \n in your patterns when working with multiline strings.