如何在匹配模式a <style>several matches here</style> and <style>here too</style>
内找到匹配项?
示例:
/*0*/ <style>/* 1 */ 2 /**3***/4*//*
5/*6*/</style> 7/*8 <style>9*//*10*/</style>/*11*/</style>
预期比赛:
/* 1 */
,/**3***/
,/*
5/*6*/
,/*10*/
正则表达式/\/\*.*?\*\/(?=.*?<\/style>)/gs
https://regex101.com/r/Nm7joV/3也匹配STYLE标记。
更新:如果单个正则表达式可以管理STYLE标记位于...<style>.../* match </style> till here*/</style>...
之类的评论中,则会带来好处。
答案 0 :(得分:-1)
可以使用https://regex101.com/r/Nm7joV/9
执行此操作(?=<style>)|\G(?!\A)(?!</style>).*?\K(?s)/\*.*?\*/
它还包括STYLE标签在评论中的情况,例如
/*0*/ <style>/* 1 <style>*/ 2 /**3</style>***/4*//*
5/*6*/</style> 7/*8 <style>9*//*10*/</style>/*11*/</style>
匹配:
/* 1 <style>*/
,/**3</style>***/
,/*
5/*6*/
,/*10*/