开发者

ignoring whitespace/newline in regex within AS3

I'm trying to write a regex expression that will take this phrase

[[32, 120], x1y1, [object pieceP1], null]

and ultimately I need it to break everything apart s开发者_StackOverflowo that the final output ends up as

32
120
x1y1
[object pieceP1]
null

now I go this phrase which is kind of close to what I want

var re3:RegExp = / , | \ [ | \ ] /s;

however my final result with this is

32
 120

 x1y1

object pieceP1

 null

As you can see, i'm getting a ton of empty lines and white space... how can I modify my expression so that these empty lines and white space are removed? I read that having x at the end of the expression would work but this didn't do anything.


You can filter your results after splitting. I've altered your RegExp slightly

var str:String = "[[32, 120], x1y1, [object pieceP1], null]";
var bits:Array = str.split(/[\[\],]+\s?/).filter( function( x ) { return !!x });

// ["32", "120", "x1y1", "object pieceP1", "null"]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜