开发者

Extract Multiple Strings from Paragraph

开发者 https://www.devze.com 2023-04-07 14:27 出处:网络
How do I extract more than one email from a paragraph and output the result to a console? var pattern:RegExp = (/^\\b[-._0-9a-zA-Z]+@[-._0-9a-zA-Z]+[\\.]{1}[0-9a-zA-Z]+[\\.]?[0-9a-zA-Z]\\b$/i);

How do I extract more than one email from a paragraph and output the result to a console?

var pattern:RegExp = (/^\b[-._0-9a-zA-Z]+@[-._0-9a-zA-Z]+[\.]{1}[0-9a-zA-Z]+[\.]?[0-9a-zA-Z]\b$/i);
var asd:String;
开发者_如何转开发asd=tt.text;
trace(asd.match(pattern));


Try this regex pattern instead: ([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})


You need to add a g to the end of your RegExp pattern to make it a global search, and hence return all the matches, which will be returned in an Array. Eg.,

var pattern:RegExp = (/foo/g);

BTW, Grant Skinner has a great Flex/AIR app to develop and test regex patterns: Online Version

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号