請嘗試以下代碼。
var myPattern:RegExp = /(?<==).+(?=&)/;
var str:String = "http://vandooren.be?v=123456&test=123";
var result:Array = myPattern.exec(str);
trace(result[0]); //123456
var myPattern:RegExp = /(?<==).+(?=&)/;
var str:String = "youtube.com/watch?v=nCgQDjiotG0&feature=youtube_gdata";
var result:Array = myPattern.exec(str);
trace(result[0]); //nCgQDjiotG0
Assertions
foo(?=bar) Lookahead assertion. The pattern foo will only match if followed by a match of pattern bar.
foo(?!bar) Negative lookahead assertion. The pattern foo will only match if not followed by a match of pattern bar.
(?<=foo)bar Lookbehind assertion. The pattern bar will only match if preceeded by a match of pattern foo.
(?<!foo)bar Negative lookbehind assertion. The pattern bar will only match if not preceeded by a match of pattern foo.
有一個URI/URL(分析器)類?否則,你可以在'?'處取出最後一個標記,然後沿'&'分開,然後對於每個標記,找到以名稱開頭並沿着= =分開的標記。 – nhahtdh 2012-08-07 06:55:59
是的,我會從URL這個變量得到這麼愚蠢我沒有想到這個 – 2012-08-07 07:08:31