$re = '/"SgxEpoch":\s*(\"([^0].{31}|.[^0].{30}|.{2}[^0].{29}|.{3}[^0].{28}|.{4}[^0].{27}|.{5}[^0].{26}|.{6}[^0].{25}|.{7}[^0].{24}|.{8}[^0].{23}|.{9}[^0].{22}|.{10}[^0].{21}|.{11}[^0].{20}|.{12}[^0].{19}|.{13}[^0].{18}|.{14}[^0].{17}|.{15}[^0].{16}|.{16}[^0].{15}|.{17}[^0].{14}|.{18}[^0].{13}|.{19}[^0].{12}|.{20}[^0].{11}|.{21}[^0].{10}|.{22}[^0].{9}|.{23}[^0].{8}|.{24}[^0].{7}|.{25}[^0].{6}|.{26}[^0].{5}|.{27}[^0].{4}|.{28}[^0].{3}|.{29}[^0].{2}|.{30}[^0].|.{31}[^0])\"|"")/';
$str = '"SgxEpoch": "00000000000000000000000000000000"
"SgxEpoch": "00000000000000000000000000001000"
"SgxEpoch": "00000000000000000000000000000000"
"SgxEpoch": ""
"J8G9SQFG374OI2K4NKRPADZBERUFSZBU"
[]$ for i in {1..30}; do echo "\\"SgxEpoch\\": \\"$(cat /dev/urandom | tr -dc \'A-Z0-9\' | fold -w 32 | head -n 1)\\""; done;
"SgxEpoch": "RG1RLP2EVNB8HDNWH9GV4TJDB531WLXB"
"SgxEpoch": "GVHUIQCS92Y4D22AV7MVWD3T4PNSG1CA"
"SgxEpoch": "6XNYUHV542BZ641G7NR5J3TGIZ14805T"
"SgxEpoch": "WJAFO7E45QR0QVHAS9OII5LSZ2BJRRDT"
"SgxEpoch": "QSXAOKMVGZ3UT7R6K9II8W42SIKJB4CH"
"SgxEpoch": "C7HC5SMK85CSZ45OXW29D6JAHT4ZA2H7"
"SgxEpoch": "XRV62S6YQ5BM25NKK8VGIL31GRO4KAQC"
"SgxEpoch": "2ZPD3Y2U4RS5YQFKK36F6BJDTOCFK1PL"
"SgxEpoch": "I7UONV2YA6H2S245KPPQAASG801BB23A"
"SgxEpoch": "X7OXH645EYWTISMTT5P9X46PUOMA2EFW"
"SgxEpoch": "LF2ASFTRLY1Y1NQIO89G6GS3VHM7Y2YX"
"SgxEpoch": "KH0KU5213C3ET7QR99K1D1TX8N6K8JG9"
"SgxEpoch": "FOXZ8F490134F1Q9ARW5JAH50KXVC1ST"
"SgxEpoch": "BSFDYP5T9SUNAK097LEJH2JFAH1BVO10"
"SgxEpoch": "13IR5STLX3XIRA7D0XDSGWSTUPKBIUF4"
"SgxEpoch": "BTQULR3SH5C5I6I6JNVDG5OPCWZYIO21"
"SgxEpoch": "DBG0DK9R9S817XWJQU76ZS1C4NB9MH0D"
"SgxEpoch": "6KOJH14I94WGP7WIWSXSPIG0EMEZGN7B"
"SgxEpoch": "9A9XJEOQ157KMPQPXNZKUOZJBN9N1X82"
"SgxEpoch": "SQXDD61TZX0PZZI40A83B0F0WYAKJ4ED"
"SgxEpoch": "7XQ1DLU186KZ66ZTU393T0IT301UBHVY"
"SgxEpoch": "4M0M5Y5MOMG2RPC5153JXUY14B31O19P"
"SgxEpoch": "JY1HPMZYSCGGBUG0FG5TH8R4EXSE57EZ"
"SgxEpoch": "74O8E3WPY26ASOHM7E91KNV84AZ8ZNTM"
"SgxEpoch": "EOYJPEBTDDFI3T2YDFT16PZLJLOAQ0NK"
"SgxEpoch": "0BVQ6GQF3Q12SCW4GGDMCQQXBCDRBL9Z"
"SgxEpoch": "1L91SIZYM7ANWJE1TZX7U64QEMW267U1"
"SgxEpoch": "E0CUT3MIJLZECDP9VE63IO4TDVPNOBJ2"
"SgxEpoch": "KJYF7SZUSBGZDAIT5366YVQ63ECEMGQ1"
"SgxEpoch": "P4SV9WTRL0HGOEAD48K3E1ZHP1ZTRDKN"
[]$
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php