[英]How do I apply a regex on a Parenthesized Substring Matches?
我有HTML內容,我這樣做是為了獲得Textual內容。
string='<img src="Randomz" alt="Randomz Image">Randomz is the name of the image</img><img src="Randomz" alt="Randomz Image">Randomz is the name of the image</img><img src="Randomz" alt="Randomz Image">Randomz is the name of the image</img><img src="Randomz" alt="Randomz Image">Randomz is the name of the image</img>'
re=(/([<][^<]+>)([^<]+)([<][^<]+>)/g);
newstr=string.replace(re,"$1$2$3");
這給了我原始的字符串。
我的問題是我需要在newstr=string.replace(re,"$1$2$3"
)之前應用另一個string.replace(regex,$2)
)
也就是說,在應用最終解決方案之前,我需要在參數化的catch上應用另一個正則表達式。
不知道您在這里做什么,但是我想您正在尋找replace
回調:
string='<img src="Randomz" alt="Randomz Image">Randomz is the name of the image</img><img src="Random'
re=(/([<][^<]+>)([^<]+)([<][^<]+>)/g);
newstr=string.replace(re, function($0, $1, $2, $3) {
$2 = do_something_with($2);
return $1 + $2 + $3;
});
另外,正則表達式不是進行html轉換的最佳工具。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.