string - Using regex to split() -
i've been trying regular expression work code while , wondering if knows better way.
i've got big chunk of text parse , want split array based on lines. straightforward, right? using regex:
var re:regexp = /\n/; arr = content.split(re);
easy. want split on lines not have space after them. figured i'd use \s character match non-space character after \n.
var re:regexp = /\n\s/; arr = content.split(re);
however, removes first letter of every line i'm splitting (because it's matching letters).
what's best way to:
- ignore spaces using caret (i tried
/\n^\' '/
no luck)? - not lose
\s
character when splitting string array?
use lookahead in pattern (so \s symbol won't consumed split separator):
var re:regexp = /\n(?=\s)/; arr = content.split(re);
Comments
Post a Comment