You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

正则表达式需求:匹配.scss前无-map的文件名及问题求助

Fixing Your SCSS Filename Regex

Let's break down why your original regex [a-zA-Z]+(?!-map).scss isn't working, then fix it with reliable solutions.

What's Wrong With the Original Regex?

  1. Missing full-filename anchors: Without ^ (start) and $ (end) markers, your regex matches substrings inside filenames instead of the whole thing. For example, in something-map.scss, it will latch onto the map.scss portion, causing false positives.
  2. Too restrictive character set: [a-zA-Z]+ only matches letters, so it can't handle hyphens in filenames like something-something.scss—it stops at the first hyphen and fails to match the full filename.

Working Solutions

Option 1: Negative Lookahead (Most Universal)

This regex explicitly excludes filenames ending with -map.scss while ensuring they still end with .scss:

^(?!.*-map\.scss$).*\.scss$
  • ^ anchors the match to the start of the filename
  • (?!.*-map\.scss$) is a negative lookahead that blocks any filename ending with -map.scss
  • .*\.scss$ matches any characters followed by .scss at the end of the filename

Option 2: Negative Lookbehind (For Engine-Specific Use)

If your regex tool supports fixed-length lookbehinds (like JavaScript, Python, or grep with -P), this checks directly that .scss isn't preceded by -map:

.*(?<!-map)\.scss$
  • .* matches all characters leading up to the end of the filename
  • (?<!-map) is a negative lookbehind that verifies the 4 characters before .scss aren't -map
  • \.scss$ ensures the filename ends with .scss

Testing Against Your Examples

  • something-something.scss: Both regexes match ✅
  • something-map.scss: Both regexes do not match ✅
  • something.scss: Both regexes match ✅

内容的提问来源于stack exchange,提问作者user12023283

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:05:01