开发者

Regular Expression Help AS3?

I am working on a regular expression and I need to extract two parts of an expression that is being imported through a flashvars.

//sample data similar to what comes in fro开发者_StackOverflow中文版m the flashvars. Note that the spaces are not after the and symbol, they are there because the html strips it.
var sampleText:String = "height1=60& amp;height2=80& amp;height3=95& amp;height4=75& amp;"

var heightRegExp:RegExp = /height\d/g;   //separates out the variables

var matches:Array = sampleText.match(heightRegExp);

Now I need help isolating the values of each variable and putting them in an array...For instance, 60, 80, etc. I know I should be able to write this regular expression, but I just can't get the exec expression right. Any help would be really appreciated!


sorry for not answering the question with regexes directly. I would do this:

var keyvalues:Array = sampleText.split("& amp;");
var firstkey:String = keyvalues[0].split("=")[0];
var firstvalue:String = keyvalues[0].split("=")[1];

Would that help beside the fact, that it is not using RegEx?


Neither the =, & or the ; are special characters, so I think you can use

=|&

in a split call and then the values will be in the odd indices and the height2 style names would be in the even indices.


You can use URLUtil.stringToObject()

Something like this should work:

var s:String = "name=Alex&age=21";
var o:Object = URLUtil.stringToObject(s, "&", true);

However, if you're just getting the flashvars, you should pull them from the loaderInfo of the root.

this.root.loaderInfo.parameters;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜