mardi 20 décembre 2016

Is there a method that returns only the match or first variable match of a RegEx in ActionScript or null?

Is there a method yet that returns only a match and null if there is no match?

It may be a brain freeze but is there a method that just returns the match and null if not?

For example, if I want to just return the first variable or null otherwise:

var value:String = "image/png".toLowerCase();
var result:String = value.find(/image/(png|jpg|jpeg|gif)/);

if (result=="png") {
    // do something
}

I know there's replace and exec and match and they return arrays etc but I'm just looking for a method that returns my first match or null.

If there isn't this a function like this, I wish there was. How to god I wish there was.

Aucun commentaire:

Enregistrer un commentaire