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

如何在Java[关闭]中删除字符串中的几个特殊字符

  •  -1
  • azaveri7  · 技术社区  · 7 年前

    我有一个输入字符串

    ${URL:URL=https://example.com/private/imgs/ROHAN_ZAVERI.jpg}
    

    我希望输出字符串如下:

    https://example.com/private/imgs/ROHAN_ZAVERI.jpg
    

    请让我知道正则表达式,用Java 8从输入字符串中删除几个特殊字符。

    3 回复  |  直到 7 年前
        1
  •  0
  •   Paolo    7 年前

    https?[^}]*(?=})
    
    • https http s
    • [^}]* }
    • (?=})

    public static void main (String[] args) throws java.lang.Exception
        {
            String str = "${URL:URL=https://example.com/private/imgs/ROHAN_ZAVERI.jpg}";
            String patternstr = "https?[^}]*(?=})";
    
            Pattern pattern = Pattern.compile(patternstr);
            Matcher matcher = pattern.matcher(str);
            if (matcher.find()){
            System.out.println(matcher.group(0)); 
            } 
        }
    

    https://example.com/private/imgs/ROHAN_ZAVERI.jpg
    

    here

        2
  •  1
  •   The Scientific Method    7 年前

    String str = "${URL:URL=https://example.com/privat/imgs/ROHAN_ZAVERI.jpg}";
    str.substring(str.indexOf('=')+1, str.length -1);
    System.out.println(str);
    

    https://example.com/privat/imgs/ROHAN_ZAVERI.jpg
    
        3
  •  0
  •   Safwan Shaikh    7 年前

    String str = "${URL:URL=https://example.com/privat/imgs/ROHAN_ZAVERI.jpg}";
    String[] spl = str.Split('=','}');
    Console.WriteLine(spl[1]);
    

    https://example.com/privat/imgs/ROHAN_ZAVERI.jpg