1

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 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);

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!

kapex
  • 28,903
  • 6
  • 107
  • 121
Shelley
  • 11
  • 2
  • 1
    are you just trying to access the properties of the flashvars string? if so, you should just use the loaderInfo.parameters object. – gthmb Sep 14 '11 at 15:00
  • No, I can access the parameters individually using the regular flashvars methods. Instead, I'd like to be able to use the string to dynamically create a reusable object. Therefore, the name/value pairs passed through will differ in purpose and will need to be parsed out to different arrays. – Shelley Sep 14 '11 at 20:56

3 Answers3

0

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?

ghost23
  • 2,150
  • 1
  • 20
  • 35
  • why not just do: var value:String = this.loaderInfo.properties['key'] ? :) – gthmb Sep 14 '11 at 15:08
  • i assume, that the string she mentions is a complete value within a key. that's why it says "& amp;" – ghost23 Sep 14 '11 at 15:14
  • The problem is that there are different types of variables coming in in the url. It is creating a dynamic table, so ultimately there will be rows and columns and headers, so I need to be able to put them in different arrays. I can't put all of the values in the same array...so I'm thinking I first need to parse out which values I want to put in which arrays. And I'll never know how many there will be. One table may have two headers and 4 rows and another may have 3 columns and one header and 5 rows...does that make sense? – Shelley Sep 14 '11 at 15:17
  • yes, it does. you could probably still work through the ONE array after the splitting and build your individual array from there, but i admit, having a clever RegEx is probably the better solution. Unfortunately i cannot give it to you right out of my head :) – ghost23 Sep 14 '11 at 15:26
0

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.

0

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;
Jacob Eggers
  • 9,062
  • 2
  • 25
  • 43