-1

I have string like this

https://example.com/offers/show?ID=d5589152-1ba7-4bab-b810-1d43e734575e&something=blabla&somethingelse=blabla2

sometimes string looks different

https://example.com/o/ABC/PP-Bin/4be93fd6-1380-4403-9945-0c5bc54d05e6?sName=Bam+2rnt

I want to extract ID from this string by number of characters. Every ID has 8-4-4-4-12 characters

MHB2011
  • 493
  • 1
  • 6
  • 17

1 Answers1

1

Try the following regular expression:

$subject = "https://example.com/offers/show?ID=d5589152-1ba7-4bab-b810-1d43e734575e&something=blabla&somethingelse=blabla2";

preg_match("/[a-zA-Z0-9]{8}\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{12}/", $subject, $matches);

print_R($matches);
Nadir Latif
  • 3,573
  • 1
  • 14
  • 23