[英]ignore text between two Strings with regex
我有一個文本,我想用正則表達式java提取文本的括號。
例如文字:
<p>Now a days, regenerative medicine(1) in stem cell(3) filed
widely <label>attractive(10) by</label> attractive by scientists(4).</p>
如果標簽標簽之間不存在括號,我想提取文本的括號。
例如上面的文本摘錄:
(1)
(3)
(4)
它不應在標簽標簽之間提取括號。
我使用以下正則表達式:
(<label>){0,1}[(\\w\\W)&&[^[</label>|\\(|\\)]]]*(\\(\\s*[(\\w\\W)&&[^\\(\\)]]+\\))
[(\\w\\W)&&[^[</label>|\\(|\\)]]]*(</label>){0,1}
public static void main(String[] args) {
String in = "<p>Now a days, regenerative medicine(1) in stem cell(3) filed widely <label>attractive(10) by</label> attractive by scientists(4).</p>".replaceAll("<label>.*</label>", "");;
//String inin = in.replaceAll("<label>.*</label>", "");
//System.out.println(inin);
Pattern p = Pattern.compile("\\((.*?)\\)");
Matcher m = p.matcher(in);
while(m.find()) {
System.out.println("(" + m.group(1) + ")");
}
}
輸出:
(1)
(3)
(4)
我只是忽略了標簽標簽中的文本,然后取了括號內的文本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.