public class HelloWorld{
public static void main(String []args){
String a = "[pollTimestamp]";
a.replaceAll("[^a-zA-Z0-9]","");
System.out.print(a);
}
}
uj5u.com熱心網友回復:
如果您想堅持當前的方法,您需要在 LHS 上將字串分配回自身:
String a = "[pollTimestamp]";
a = a.replaceAll("[^a-zA-Z0-9] ", "");
但是,以下方法可能更安全:
String a = "[pollTimestamp]";
a = a.replaceAll("\\[(.*?)\\]", "$1");
這樣,我們只針對方括號內包含的術語。其他型別的輸入將被擱置。
uj5u.com熱心網友回復:
replaceAll 方法試圖匹配非字母數字字符。a.replaceAll() 產生一個新的字串,請做另一個賦值 a=a.replaceAll()。
~ (tilde)
` (grave accent)
! (exclamation mark)
@ (at)
public class Test {
public static void main(String args[]) {
String a = "[pollTimestamp]";
System.out.print(a.replaceAll("[^a-zA-Z0-9]",""));
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/327889.html
上一篇:BUUCTF Web [極客大挑戰 2019]EasySQL
下一篇:Vulnhub靶場滲透-DC-1
