AIRIA
走进FLEX\AIR\RIA开发 中文资源
丰富WEB、桌面,未来10年发展主趋势。
    当前位置Actionscrip教程 >> AS3常用正则表达式
AS3常用正则表达式
[ 来源:[标签:出处] ] [ 作者:51as ] [ 日期:08-07-27 ] [ 浏览:次]
1.开头和结尾都用“/”,不过结尾的“/”后可以跟一些特定的标志符表达特定的意义。比如后面加g表示patterns是全局的。

2.可以用两种方式定义,例如下面两条,他们等价:

varpattern1:RegExp=/bob/i
varpattern2:RegExp=newRegExp("bob","i");

RegExp()中的两个参数,第二个参数表示标记。

3.如果regularexpression中有“/”等,需要在前面加“\”,如/1\/2/表示1/2。(就好像C 里的转义字符)

4.元字符:^$\.* ?()[]{}|他们在regularexpression中有特殊的意义。简要列表如下:

^(caret)Matchesatthestartofthestring.

$(dollarsign)Matchesattheendofthestring.

\(backslash)Escapesthespecialmetacharactermeaningofspecialcharacters.

.(dot)Matchesanysinglecharacter.

*(star)Matchesthepreviousitemrepeatedzeroormoretimes.

(plus)Matchesthepreviousitemrepeatedoneormoretimes.

?(questionmark)Matchesthepreviousitemrepeatedzerooronetime.

(and)Definesgroupswithintheregularexpression.

[and]Definesacharacterclass,whichdefinespossiblematchesforasingle
character

|(pipe)Usedforalternation,tomatcheitherthepartontheleftsideortheparton
therightside

5.元序列。在regularexpression里有特殊意义的字符序列。简要列表如下:

{n}{n,}and{n,n}Usedtoidentifyaspecificnumericquantifierorquantifierrangeforthepreviousitem

\AMatchesatthestartofthestringtowhichtheregularexpressionisapplied

\bMatchesatthepositionbetweenawordcharacterandanon-wordcharacter

\BMatchesatthepositionbetweentwowordcharacters.

\dMatchesadigit.

\DMatchesanycharacterotherthanadigit.

\nMatchesthenewlinecharacter.

\rMatchesthereturncharacter.

\sMatchesanywhitespacecharacter(aspace,tab,newline,orreturncharacter)

\SMatchesanycharacterotherthanawhitespacecharacter.

\tMatchesthetabcharacter.

\unnnnMatchestheUnicodecharacterwiththecharactercodespecifiedbythe
hexidecimalnumbernnnn.

\wMatchesawordcharacter(A–Z,a–z,0-9,or_).

\WMatchesanycharacterotherthanawordcharacter.

\xnnMatchesthecharacterwiththespecifiedASCIIvalue,asdefinedbythe
hexidecimalnumbernn.

\ZMatchestheendofthestringtowhichtheregularexpressionisapplied.Ifthestringendswithalinebreak,matchesbeforethefinallinebreak.

\zMatchestheendofthestringtowhichtheregularexpressionisapplied.Ifthestringendswithalinebreak,matchesafterthefinallinebreak.

6.regularexpression中的flags.

FlagPropertyDescription

gglobalMatchesmorethanonematch.

iignoreCaseCase-insensitivematching.

mmultilineWiththisflagset,$and^canmatchthebeginningofalineandendofaline,respectively

sdotallWiththisflagset,.(dot)canmatchthenewlinecharacter(\n).

xextendedAllowsextendedregularexpressions.

7.两个方法:exec(),test()。test()用来检测字符串是否含有所要匹配字符,返回值为boolean值。exec()用来模式匹配,并返回数组。
  翻页 :

评论

发表评论
www.AiRia.cn © 版权所有 All rights reserved.