[] How to obtain JS arrays in files using regular expressions

Source: Internet
Author: User
[Help] there is a need for regular expressions to obtain the JS array in a file, reading the JS array in a file capture file. This regular sentence can only capture one value & nbsp; Array \ (. +? \); And php does not only obtain the matching array, so we consider how to obtain the JS array in the file using & nbsp; preg_repl [help] regular expressions.
There is a requirement to read the JS array in a file capture file.
Only one value Array \ (. +? \);

In addition, php does not only obtain the matched array. Therefore, we should use the preg_replace method to replace all the data except the data that I want, and leave only what I need.

But I don't know how to implement it. please help me. Regular cropping File php array JS shared:
------ Solution --------------------
$ S = your string
Preg_match_all ('/Array \ (. + \)/sU', $ s, $ m );
Print_r ($ m );

------ Solution --------------------
$s =<<< TXT
var switchPara = new Array(26,0,1,24,25,2,6,8,2,2,4);
var VlanTagGlobalList = new Array(
0, 1, 1, 
0, 1, 1, 
0, 1, 1, 
0, 1, 1, 
0, 1, 1, 
0, 1, 1, 
0, 1, 1, 
0, 1, 1, 
0, 1, 1, 
0, 1, 0, 
0, 1, 0, 
0, 1, 0, 
0, 1, 0, 
0, 1, 0, 
0, 1, 0, 
0, 1, 0, 
0, 1, 0, 
0, 1, 0, 
0, 1, 0, 
0, 1, 0, 
0, 1, 0, 
0, 1, 0, 
0, 1, 1, 
0, 1, 0, 
0, 0, 99, 
0, 0, 99, 
0,0 );
var VlanTagGlobalTList = new Array(
0, 99, 
0, 99, 
0, 99, 
0, 99, 
0, 99, 
0, 99, 
0,0 );
var userLevel=window.parent.user[1];
//-->
TXT;
preg_match_all('/new Array\((.+?)\)/s', $s, $r);
print_r($r[1]);
Array
(
[0] =>, 4
[1] =>
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 1,
0, 1, 0,
0, 1, 0,
0, 1, 0,
0, 1, 0,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.