views:

182

answers:

4

Hello,

I need to extract in actionscript the variables from a string like /var1/var2/var3/...

Each variables can be characters or/and number and variable size.

My current regex /(\w+)/g work for the first variable but not for the others.

var matchExpression:RegExp = /(\w+)/g;
var match:Array = matchExpression.exec(browserManager.fragment);

Thank you!

+2  A: 

Regular expressions are not ideal for this. Why not use String.split()?

Chase Seibert
Thank you! You were right :)
Rothlis
A: 

I'm going to recommend Expresso 3.0 here - very easy to use and build up strings with.

Do you have a larger or better string example? i.e. will it always be varx\varx\myvarx?

/(\w+)/g doesn't seem to be working on my machine - you sure this works?

Daniel May
Is there something like that for Mac?
Rothlis
A: 

try to use this: (?<=/)(\w+)(?=/)

iburlakov
Your RegEx doesn't work if the variable names don't contain numerics.
Daniel May
Agree with Chase Seibert, Split() will be better.
iburlakov
to Daniel May: are you sure? :)
iburlakov
D'oh! My bad! I didn't place "/"s before and after. :)
Daniel May
A: 

Thank you Chase!

The solution :

var match:Array = browserManager.fragment.split("/");

Rothlis