Flash / Flex / ActionScript/Regular Expressions/lastIndex — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 11:14, 26 мая 2010
lastIndex property is set to a different value
<source lang="java">
package{
import flash.display.Sprite; public class Main extends Sprite{ public function Main(){ var reCase:RegExp = new RegExp("abc", "ig"); var sVal:String = "aBcdefabCdefABC"; var aMatch:Array = reCase.exec(sVal); trace(aMatch + " - " + reCase.lastIndex); reCase.lastIndex = 0; aMatch = reCase.exec(sVal); trace(aMatch + " - " + reCase.lastIndex); reCase.lastIndex = 0; aMatch = reCase.exec(sVal); trace(aMatch + " - " + reCase.lastIndex); reCase.lastIndex = 0; aMatch = reCase.exec(sVal); trace(aMatch + " - " + reCase.lastIndex); reCase.lastIndex = 0; aMatch = reCase.exec(sVal); trace(aMatch + " - " + reCase.lastIndex);
} }
}
</source>
read and write to this property to move the starting point of the next match
<source lang="java">
package{
import flash.display.Sprite; public class Main extends Sprite{ public function Main(){ var reCase:RegExp = new RegExp("abc", "ig"); var sVal:String = "aBcdefabCdefABC"; var aMatch:Array = reCase.exec(sVal); trace(aMatch + " - " + reCase.lastIndex); aMatch = reCase.exec(sVal); trace(aMatch + " - " + reCase.lastIndex); aMatch = reCase.exec(sVal); trace(aMatch + " - " + reCase.lastIndex); aMatch = reCase.exec(sVal); trace(aMatch + " - " + reCase.lastIndex); aMatch = reCase.exec(sVal); trace(aMatch + " - " + reCase.lastIndex); } }
}
</source>
The lastMatch property is the string containing the last match made by the regular expression
<source lang="java">
package{
import flash.display.Sprite; public class Main extends Sprite{ public function Main(){ var reCase:RegExp = new RegExp("def", "gi"); var sVal = new String("abcdefghi"); var sMatches:Array = sVal.match(reCase); trace(reCase.lastMatch); // Displays: def } }
}
</source>