• 【设为首页】
  • 【收藏闪客居】
当前位置:主页>FLASH AS 编程>AS基础篇>AS 3.0>文章内容
  • as3使用正则

  • 来源:网络 作者: 2007-08-15 【

1.开头和结尾都用“/”,不过结尾的“/”后可以跟一些特定的标志符表达特定的意义。比如后面加g表示patterns是全局的。

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

var pattern1:RegExp = /bob/i

var pattern2:RegExp = new RegExp("bob", "i");

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

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

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

^ (caret) Matches at the start of the string.

$ (dollar sign) Matches at the end of the string.

\ (backslash) Escapes the special metacharacter meaning of special characters.

. (dot) Matches any single character.

* (star) Matches the previous item repeated zero or more times.

+ (plus) Matches the previous item repeated one or more times.

? (question mark) Matches the previous item repeated zero or one time.

( and ) Defines groups within the regular expression.

[ and ] Defines a character class, which defines possible matches for a single

character

| (pipe) Used for alternation, to match either the part on the left side or the part on

the right side

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

{n}{n,} and {n,n} Used to identify a specific numeric quantifier or quantifier range for the previous item

\A Matches at the start of the string to which the regular expression is applied

\b Matches at the position between a word character and a non-word character

\B Matches at the position between two word characters.

\d Matches a digit.

\D Matches any character other than a digit.

\n Matches the newline character.

\r Matches the return character.

\s Matches any whitespace character (a space, tab, newline, or return character)

\S Matches any character other than a whitespace character.

\t Matches the tab character.

\unnnn Matches the Unicode character with the character code specified by the

hexidecimal number nnnn.

\w Matches a word character (A–Z, a–z, 0-9, or _).

\W Matches any character other than a word character.

\xnn Matches the character with the specified ASCII value, as defined by the

hexidecimal number nn.

\Z Matches the end of the string to which the regular expression is applied.If the string ends with a line break, matches before the final line break.

\z Matches the end of the string to which the regular expression is applied.If the string ends with a line break, matches after the final line break.

6.regular expression 中的 flags.

Flag Property Description

g global Matches more than one match.

i ignoreCase Case-insensitive matching.

m multiline With this flag set, $ and ^ can match the beginning of a line and end of a line, respectively

s dotall With this flag set, . (dot) can match the newline character (\n).

x extended Allows extended regular expressions.

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




上一篇:ActionScript 3外部swf文件载入   下一篇:使用as3生成gif动画
  • 用户名:新注册) 密码: 匿名评论
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)

Copyright © 2006-2008 flashas.net All Rights Reserved.
网站内容咨询: admin#flashas.net (#为@) 联系QQ:40777822 浙ICP备06033001号
(本网站最佳浏览解析度为1024*768, 建议使用IE 6.0或以上版本浏览器。)