0
我有以下字符串取兩個標籤
String s = "{s}lorem ipsum{/s}
explanation for lorem ipsum
{s}dolar sit amet{/s}
explanation for dolar sit amet";
我想解析它以兩種方式之間的DATAS。我想要獲取{s} {/ s}標籤和{s} {/ s}未包含的文本內的文本。
我試過下面的代碼。
String firstRemovePattern = "\\{" + "\\}";
String replacedWithFirstPattern = s.replaceAll(firstRemovePattern, "");
但上面的代碼不會獲取預期的字符串。我怎樣才能解決這個問題?
如果文本不以標籤組開頭,該怎麼辦:https://regex101.com/r/HBka56/10? –
@DmitryEgorov:[在這種情況下檢查這個正則表達式](https://regex101.com/r/HBka56/11) – anubhava