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:

  1. ignore spaces using caret (i tried /\n^\' '/ no luck)?
  2. 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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -