[英]Regular expression for __(' … ')
我正在嘗試使用正則表達式,但遇到了問題:我想匹配所有以
__(' or __("
並以
') or ")
我嘗試過
/__\(['"][^']*['"]\)/g and /__\(['"].*['"]\)/g
但他們都對此示例文本有疑問:
text that should not match
__('all text and html<a href="#">link</a> that should match') text that should not match __('all text and html<a href="#">link</a>')
__("all text and html<a href="#">link</a>") text that should not match __("all text and html<a href="#">link</a>")
other text that should not match
誰擁有獲獎的RegExp?
我猜您想要非貪婪的匹配,那么最好的解決方案是使用:
/__\(['"][^']*?['"]\)/g
此外,轉義單引號和雙引號可能會有所幫助:
您可以在此regex101上進行檢查
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.