Regex : Extracting variables from a string like /var1/var2/var3/

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!

Upvotes: 0

Views: 652

Answers (4)

iburlakov
iburlakov

Reputation: 4232

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

Upvotes: 0

Thank you Chase!

The solution :

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

Upvotes: 0

Daniel May
Daniel May

Reputation: 8226

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?

Upvotes: 0

Chase Seibert
Chase Seibert

Reputation: 15851

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

Upvotes: 2

Related Questions