Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

as3 replaceAll insensitive

I have this as3 function

public static function StringReplaceAll( source:String, find:String, replacement:String ) : String {
      return source.split( find ).join( replacement );
}

Works fine: any idea how to make it case insenstive ? Regards

like image 762
yarek Avatar asked Dec 02 '22 00:12

yarek


1 Answers

Just use the String#replace() function.

for example:

trace("HELLO there".replace(/e/gi, "a"));
//traces HaLLO thara

The first argument in the replace function is a regular expression. You'll find information about them all over the web. And there's this handy tool from Grant Skinner called Regexr with which you can test your regular expressions ActionScript style.

The part between the two forward slashes (/) is the actual regex.

  • The 'g' after the regex means "replace globally" (i.e. all occurrences of the letter 'e' in the example, without the 'g' it would just replace the first occurrence).
  • The 'i' means "do a case insensitive search" (in the example, without the 'i' the capital E wouldn't have been replaced).

Note that /e/gi is actually just a shorthand for new RegExp("e", "gi")

like image 83
RIAstar Avatar answered Dec 20 '22 10:12

RIAstar