简体   繁体   English

正则表达式-如果模式以//开头则避免匹配-注释掉

[英]Regex - avoid match if pattern prefixed with // - comment outs

I have the following regex (JS.match) pattern /@import ['"](.*)['"]/g allowing for the external files inclusion so eg 我有以下正则表达式(JS.match)模式/@import ['"](.*)['"]/g允许包含外部文件,例如

@import "/my/path" returns /my/path @import "/my/path"返回/my/path

all works as expected but I would like to enable commenting out with // and /* */ 一切都按预期工作,但我想启用///* */注释掉

so if string contains //@import "/my/path" or /* @import "/my/path" */ then there should be NO match. 因此,如果字符串包含//@import "/my/path"/* @import "/my/path" */则应该没有匹配项。

any ideas? 有任何想法吗?

(?![/*])[^/* ]@import ['"](.*?)['"]

Live demo 现场演示

Update 更新

(?![/*])[^/* ]@import ['"](.*?)['"](?![^/]*?\*\/)

Live demo 现场演示

Update #2 更新#2

Use below regex with m flag: 在带有m标志的正则表达式下面使用:

(?:(?![/*]])[^/* ]|^ *)@import ['"](.*?)['"](?![^*]*?\*\/)

Live demo 现场演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM