views:

31

answers:

1

I admit, after all these years I suck at regex. I am hoping someone and quickly help me with this.

var str = "11 FT 0 IN | 10' ( +$2,667.00 )";
var match = str.match(/**no clue what to do**/g);

// results needed
match[0] = "11 FT 0 IN";
match[1] = "10'";
match[2] = "( +$2,667.00 )";
+2  A: 
 /^\s*((?:\s*[^\s|])+)\s*\|\s*((?:\s*[^\s(])+)\s*(.+)$/

The results are in matches[1] to [3]. The [0] is always the whole match.


 ^                 # start of string
 \s*               # initial spaces, if any
 ((?:\s*[^\s|])+)  # non-pipe-or-space characters,
                   #   preceded by some spaces (the "11 FT 0 IN")
 \s*               # more optional spaces
 \|                # the pipe character
 \s*               # even more optional spaces
 ((?:\s*[^\s(])+)  # non-open-parenthesis-or-space characters,
                   #   preceded by some spaces (the "10'")
 \s*               # more or more optional spaces
 (.+)              # just chomp everything beyond (the "( +$2,667.00 )")
 $                 # end of string
KennyTM
Thanks Kenny. Can you break it down a little so I, and other, can understand what exactly is going on here?
Ryan