我承认,这些年来我一直在使用正则表达式。我希望有人能尽快帮助我。

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 )";

最佳答案

 /^\s*((?:\s*[^\s|])+)\s*\|\s*((?:\s*[^\s(])+)\s*(.+)$/


结果在matches[1][3]中。 [0]始终是整个匹配项。



 ^                 # 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

09-25 19:55