[英]Regex get last word of pattern
我有這串
<p> this is some text</p>
可以任意次數
匹配我正在使用正則表達式(?<=<p.*?>* )(.*)(?=</p>)
但是我得到的 this is some text
作為輸出
如何獲得this is some text
編輯
很抱歉,我的字符串是<p class='randomstring'>a) this is some text</p>
代替a)
<p class='randomstring'>a) this is some text</p>
,而不是a)
有時會有數字。
您可以使用此正則表達式:
(?<=<p[^>]*>)(?: )+(.*)(?=</p>)
並抓住與您匹配的捕獲的第一組 ,那就是:
this is some text
編輯:根據您編輯的問題,請嘗試此正則表達式:
(?<=<p[^>]*>)[^)]*\) *(?: )+(.*)(?=</p>)
您可以使用下面的正則表達式,該正則表達式使用可變長度正向后看。
(?<=<p[^>]*>(?: )+)\b.*?(?=</p>)
這應該只匹配字符串, this is some text
更新:
(?<=<p[^>]*>\w*\)(?: )+)\b.*?(?=</p>)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.