Actionscript 3 正则表达式帮助AS3?

Actionscript 3 正则表达式帮助AS3?,actionscript-3,flash-cs5,flash-cs4,flash-cs3,Actionscript 3,Flash Cs5,Flash Cs4,Flash Cs3,我正在处理一个正则表达式,需要提取通过flashvars导入的表达式的两部分 //sample data similar to what comes in from 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&am

我正在处理一个正则表达式,需要提取通过flashvars导入的表达式的两部分

//sample data similar to what comes in from 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);

现在我需要帮助隔离每个变量的值并将它们放入数组中…例如,
60、80、
等等。我知道我应该能够编写这个正则表达式,但我就是无法正确地获得exec表达式。任何帮助都将不胜感激

很抱歉没有直接用正则表达式回答这个问题。我会这样做:

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

除了不使用RegEx这一事实之外,这还有帮助吗?

无论是=、&还是;都是特殊字符,所以我想你可以用

=|&
在拆分调用中,然后值将在奇数索引中,height2样式名称将在偶数索引中。

您可以使用

像这样的方法应该会奏效:

var s:String = "name=Alex&age=21";
var o:Object = URLUtil.stringToObject(s, "&", true);
然而,如果你刚刚得到FlashVar,你应该把它们从根部拔出

this.root.loaderInfo.parameters;

您正在尝试访问flashvars字符串的属性吗?如果是这样,您应该只使用loaderInfo.parameters对象。不,我可以使用常规的flashvars方法单独访问参数。相反,我希望能够使用字符串动态创建可重用对象。因此,传递的名称/值对的用途不同,需要解析为不同的数组。为什么不这样做:var-value:String=this.loaderInfo.properties['key']?:)我假设她提到的字符串是一个键中的完整值。这就是为什么它会说“&;”问题是url中有不同类型的变量。它正在创建一个动态表,所以最终将有行、列和标题,所以我需要能够将它们放在不同的数组中。我不能把所有的值放在同一个数组中…所以我想我首先需要解析出我想放在哪个数组中的值。我永远也不知道会有多少。一个表可能有两个标题和4行,另一个表可能有3列,一个标题和5行……这有意义吗?是的,有意义。在拆分之后,您可能仍然可以使用一个数组并从中构建您的单个数组,但是我承认,使用一个聪明的正则表达式可能是更好的解决方案。不幸的是,我不能马上把它给你:)