[英]Extract a string between 2 characters of the same character
我理解如何在[和],或()等兩種不同類型的字符串之間提取字符串...
但我不知道的是如何在1個字符之間獲得多個/所有字符串。 例如:
the *big* brown fox *jumps over* the *lazy* **dog**
它應返回“*”:
big
jumps over
lazy
它也應該返回“**”:
dog
所有庫,正則表達式模式等都不支持這樣的功能。
String str="the *big* brown fox *jumps over* the *lazy* **dog**"
str = str.replace("**", "*");
然后執行您正在使用的提取方法
String test = "the *big* brown fox *jumps over* the *lazy* **dog**";
StringTokenizer st = new StringTokenizer(test,"*");
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.