Php 使用preg_匹配提取Javascript对象参数

Php 使用preg_匹配提取Javascript对象参数,php,regex,preg-match,Php,Regex,Preg Match,我试图从JS对象中提取要处理的视频信息: var playerSettings = {flashplayer: "jwplayer.flash.swf",width: 640,height: 480, skin: "five.xml",primary: "flash",autostart: "true",abouttext: "this video",aboutlink: "www.video.com",startparam: "ec_seek", playlist: [{sources: [{

我试图从JS对象中提取要处理的视频信息:

var playerSettings = {flashplayer: "jwplayer.flash.swf",width: 640,height: 480,
skin: "five.xml",primary: "flash",autostart: "true",abouttext: "this video",aboutlink: "www.video.com",startparam: "ec_seek",
playlist: [{sources: [{ type: "mp4", file: "http://video-media.com/T/4/I/N/T4INzPOLNGF.480.mp4?2a8283553d5cb07b981d3deae8444eb54ae8832fd5c37be54baba4c6d41e2fb5f374d06c9f5d7609a96b96ab5fec4fd487af4cde9304969fce3913c656adb1960d3c6f7ffb87649b34d8a0a87a14b2b1243663709429bdfae86a3e9521bf631393b37c2eb2c42f1e654dbeec41579aaf3f3b8075e318&150"}],"previewer.file" : "http://i-sec.video-media.com/T/4/I/N/T4INzPOLNGF-sprite.jpg"}],
plugins: {"js/videopreviewer-2.0.js": {frameWidth: "156",frameHeight: "117",columns: "1",rows: "50",
totalFrames: 50,loadOnStart: true,thumbnailsOffset: 2,tooltip: {hook: false,cornerRadius: 10,padding: 5,paddingTop: 0,paddingBottom: 6,color: "#CCCCCC"}}}};
我正试着去

{ type: "mp4", file: "http://video-media.com/T/4/I/N/T4INzPOLNGF.480.mp4?2a8283553d5cb07b981d3deae8444eb54ae8832fd5c37be54baba4c6d41e2fb5f374d06c9f5d7609a96b96ab5fec4fd487af4cde9304969fce3913c656adb1960d3c6f7ffb87649b34d8a0a87a14b2b1243663709429bdfae86a3e9521bf631393b37c2eb2c42f1e654dbeec41579aaf3f3b8075e318&150"}
从上述设置

我尝试的是:

preg_match_all('/sources: \[^(.*)&\]/', $scriptText, $match);
var_dump($match);

但它给出了空数组

如果坚持使用正则表达式,请在不使用^(匹配行首)和&(匹配符号)的情况下进行尝试:

而且

他很贪婪,所以你可能会得到比你预想的更多的东西

(.*?)
实际上会在一开始就停止]这可能是你想要的。我也喜欢

([^\]]*)

为此,除了“]”之外的任何字符的贪婪匹配都可以更容易阅读。

您可以改用它吗?:耸耸肩:@KevinM1,我认为PHP不识别JS字符串。如果您坚持使用正则表达式,请删除^(匹配行的开头)和&(匹配符号)@TomMcClure,这很有效。。哈哈:)@KevinM1,你是否建议使用
str\u replace
删除JS特定的构造?
(.*?)
([^\]]*)