I need to create an expression that can "Enclose" a substring. The content of that substring can then be taken, modified, and replace the original substring.
For example:
var str:String = "The balloon is <start>red||blue||green<end> and is <start>rather large||very small<end> in size.";
I don't know to create an expression that consumes the content of the string, from Start until it encounters End.
From there, I need to pull a copy of that substring, modify it (In this case, select a random section, which I already know how to do), and then replace this individual substring before going onto the second substring.
Edit:
Thanks to the redirect, I've written a mostly-working function that produces close to the result I'm looking for, the issue comes at the tail end when replacing the substrings. Here's my function:
function substringfunction(texts:String):void {
var expression:RegExp = /(?<=<start>)(.*?)(?=<end>)/g;
var arrayResult:Array = texts.match(expression);
var arrayLength:Number = arrayResult.length;
var i:Number = 0;
for(i = 0; i < arrayLength; i++) {
var arr:Array = arrayResult[i].split("||");
var choice:String = (arr[Math.floor(Math.random() * arr.length)]);
trace(choice);
texts = texts.replace(expression, choice);
}
trace(texts);
}
As you'll find, it replaces all expressions with the choice for every cycle, until they eventually become the random choice for the lattermost array row. I attempted to use an expression that eschews the global flag, but that produced the same result, except now only affecting the first substring, so I'm out of ideas.
Any further assistance would be greatly appreciated.