代码之家  ›  专栏  ›  技术社区  ›  Ale

正则表达式中的删除

  •  -1
  • Ale  · 技术社区  · 8 年前

    对于此表达式:

    "created":"589c8377576a33706397f3f4" 
    

    我写这个正则表达式:

    output_row.json.replaceAll("\"created\":\"589c8377576a33706397f3f4\"","");
    

    [[:xdigit:]] .

    我试过了,但没用!

    output_row.json.replaceAll("\"created\":\"[[:xdigit:]]\"",""); 
    

    2 回复  |  直到 8 年前
        1
  •  2
  •   Robert    8 年前

    [[:xdigit:]] 正好是一个十六进制数字。添加 + * 匹配0到n个十六进制数字。

        2
  •  0
  •   Ale    8 年前

    最后我找到了答案:

    //replace the value of the key created 
    output_row.json = output_row.json.replaceAll("\"created\":\"[a-zA-Z0-9]+\"","\"created\":\"" + formatted + "\"");
    

    我不知道为什么Talend editor不接受这个类: [[:xdigit:]] 可能不是特定于Java?