package ch17_1 { import flash.display.MovieClip; public class Text2 extends MovieClip { public function Text2() { var myP1:RegExp = /a/; 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)); trace(); myP1 =/a$/; 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 匹配:true str1 匹配:false str2 匹配:false str3 匹配:false str4 匹配:true
原文链接:https://www.f2er.com/regex/362643.html