开发者

How do I find the next nonalphanumeric or '_' character in a string in AS3?

开发者 https://www.devze.com 2023-04-08 12:31 出处:网络
I need to strip a string from another and get the remnants. The string开发者_开发问答 I need to strip is a Twitter username, so it can be variable length, but always starts with an \'@\' and can only

I need to strip a string from another and get the remnants. The string开发者_开发问答 I need to strip is a Twitter username, so it can be variable length, but always starts with an '@' and can only contain alphanumeric characters or underscores.

For example, the original string might be "@username: tweeting about stuff" and I need to get out of that ": tweeting about stuff".

I don't have any experience with Regular Expressions, but I'm lead to believe that it can be done using these?

Thanks in advance for any help!


Use this regex:

var str:String = "@username: tweeting about stuff";
var pattern:RegExp = /(?<=@)[\w\d]+\b/
var matches:Array = str.match(pattern);
trace(matches[0]);


var str:String = "@username: tweeting about stuff";

trace( str.split(':')[0] )// should always be the username 
trace( str.split(':')[1] )// unless the tweet had more colons in it this will be the message
0

精彩评论

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

关注公众号