开发者

Javascript RegEx Help

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,6开发者_StackOverflow67.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*(.+)$/

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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜