正则表达式匹配雅虎管道中的小数n后的所有内容?

时间:2014-01-06 23:11:58

标签: regex expression pipe yahoo

您好我使用雅虎管道,我需要一些帮助。我试图在随机数的第二个数字之后匹配所有内容。

示例:

25.6444841218545我需要匹配“44841218545”,所以输出量为“25.64”

544.012我需要匹配“2”,输出将是“544.01”

感谢。我真的需要一些帮助。

2 个答案:

答案 0 :(得分:0)

鉴于您尝试搜索的数据描述不佳,这是我能给出的最佳猜测:

(\d+\.\d{0,2})

细分:

(            # Capture
    \d+      # More than one digit
    \.       # Followed by a literal dot (.)
    \d{0,2}  # And between 0 and 2 more digits (incase the random number is truncated).
 )

答案 1 :(得分:0)

我同意@Lego Stormtroopr的回答是做你想要完成的事情的最佳方式,但是根据你在问题中的描述进行匹配,你可以这样做:

var str = "25.6444841218545";

var result = str.replace(/([0-9]+\.[0-9]{2})[0-9]*/, "$1");

console.log("result = "+result);

输出:R t

result = 25.64