![](/img/trans.png)
[英]How to remove the square brackets at the beginning and end of the special characters String?
[英]How to Remove special Characters from Java String at the end and at the beginning
假設我有一個字符串
String examplestring = "%,.&/)"hello, mynameis, Fatih-Mehmet?And yours.insidedot.2874d3"( )§("
我想提取核心部分
String goalstring = "hello, mynameis, Fatih-Mehmet?And yours.insidedot 2874d3"
因此,將所有特殊字符保留在核心中,但從字符串的末尾和開頭刪除所有特殊字符,我怎么能做到這一點?
提前致謝
假設您想從字符串中提取單個雙引號術語,並在開頭或結尾處被其他可能的內容包圍,我們可以將您的要求表述為:
String examplestring = "%,.&/)\"hello, mynameis, Fatih-Mehmet!And yours?insidedot.2874d3\"(.)§(";
examplestring = examplestring.replaceAll("^[^\"]*\"|\"[^\"]*$", "");
System.out.println(examplestring);
// hello, mynameis, Fatih-Mehmet!And yours?insidedot.2874d3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.