package ch17_1 { import flash.display.MovieClip; public class Text extends MovieClip { public function Text() { var myP1:RegExp = new RegExp("abc"); var myP2:RegExp =/abc/; //两种定义完全等效 var str1:String ="123"; var str2:String ="bc"; var str3:String ="abc"; var str4:String ="cba"; trace("str1 匹配:"+myP1.test(str1)); trace("str2 匹配:"+myP1.test(str2)); trace("str3 匹配:"+myP1.test(str3)); trace("str4 匹配:"+myP1.test(str4)); } } }
结果:
str1 匹配:false str2 匹配:false str3 匹配:true str4 匹配:false
原文链接:https://www.f2er.com/regex/362645.html