I have a string that is similar to a path, but I have tried some regex patterns that are supposed to parse paths and they don’t quite work.
Here’s the string
f|MyApparel/Templates/Events/
I need the “name parts” between the slashes.
I tried (\w+) but the array came back [0] = "f" and [1] = "f".
I tested the pattern on http://www.gskinner.com/RegExr/ and it seems to work correctly.
Here’s the AS code:
var pattern : RegExp = /(\w+)/g;
var hierarchy : Array = pattern.exec(params.category_id);
params.name = hierarchy.pop() as String;
pattern.exec()works like in JavaScript. It resets thelastIndexproperty every time it finds a match for a global regex, and next time you run it it starts from there.So it does not return an array of all matches, but only the very next match in the string. Hence you must run it in a loop until it returns
null: