Replace with Regular Expression
package{ import flash.display.Sprite; public class Main extends Sprite{ public function Main(){ var introduction:String = "My name is A!"; trace(introduction.replace(/my name is (\w+)/gi, "$1 is my name")); } } }