【问题标题】:Regex match everything after n-th of decimalin yahoo pipes?正则表达式匹配雅虎管道中小数点后的所有内容?
【发布时间】:2014-01-06 23:11:57
【问题描述】:

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

例子:

25.6444841218545 我需要匹配“44841218545”,所以输出将是“25.64”

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

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

【问题讨论】:

  • [^\.]*\.\d{2},也许?不过,不确定正则表达式是否适用于此。

标签: regex expression pipe yahoo


【解决方案1】:

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

(\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).
 )

【讨论】:

    【解决方案2】:

    我同意@Lego Stormtroopr 的回答是完成您想要完成的工作的最佳方式,但是根据您在问题中的描述,您可以这样做:

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

    输出:r

    result = 25.64
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多