Isolate the digits after the match like this:
Code: (Demo)
$string = '{},\"employees\":{},\"idIwant\":{\"2545\":{\"attributes\":{\"offset\":9855,';
echo preg_match('~"idIwant\\\":{\\\"\K\d+~', $string, $out) ? $out[0] : 'bonk';
Output:
2545
Keeping the "
and \"
around your sought key is important so that you are matching the whole targeted keyword (no inadvertent substring matching).
\K
restarts the fullstring match so that you don't need to bloat the output array with unnecessary elements.
Php requires 3 or 4 \
to represent one in the pattern. (Here's some breakdown: https://stackoverflow.com/a/15369828/2943403)
p.s. Alternatively, you can force the leading portion of the pattern to be literally interpretted with \Q..\E
like this:
Demo
echo preg_match('~\Q\"idIwant\":{\"\E\K\d+~', $string, $out) ? $out[0] : 'bonk';
Or if you are scared off by so many metacharacters, you could reduce the stability of your pattern and just match the search string, then match one or more non-digits, then forget the previously matched characters, then match 1 or more digits:
echo preg_match('~idIwant\D+\K\d+~', $string, $out) ? $out[0] : 'bonk';