常用正则

逆向引用
var pattern:RegExp = /(\d+)-by-\1/;

非捕获组:可以使用 (?: 和 ) 来定义非捕获组
---------------------------------------
//捕获组
var pattern:RegExp = /(\w+)@(\w+).(com|org)/;
var str:String = "bob@example.com";
trace(pattern.exec(str));
// bob@example.com,bob,example,com
---------------------------------------
//非捕获组
var pattern:RegExp = /(\w+)@(\w+).(?:com|org)/;
var str:String = "bob@example.com";
trace(pattern.exec(str));
// bob@example.com,bob,example
---------------------------------------
非捕获组包括两种类型:“ 正向前查找组” 和“ 负向前查找组”。
使用 (?= 和 ) 定义正向前查找组
var pattern:RegExp = /sh(?=e)(\w*)/i;
var str:String = "Shelly sells seashells by the seashore";
trace(pattern.exec(str));
// Shelly,elly
var pattern:RegExp = /sh(?!e)(\w*)/i;
var str:String = "She sells seashells by the seashore";
trace(pattern.exec(str));
// shore,ore
---------------------------------------
(?P<name> 和 ) 可定义命名组
var myPattern:RegExp = /([a-z]+)(?P<digits>\d+)[a-z]+/;
var str:String = "a123bcd";
var result:Array = myPattern.exec(str);
trace(result.digits); // 123

var pattern:RegExp = /src\s*=\s*('|")(?P<src>(.+))\1/is;
var str:String = "<img src='' src  = \"http://cc.dd.com\" />";
var o:* = pattern.exec(str);

posted @ 2015-08-05 13:52  飞过塞北  阅读(64)  评论(0编辑  收藏  举报