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

如何用正则表达式匹配除@开头单词外的所有‘.’字符?

Regex to Match Dots Not Inside @-Prefixed Words

Got it, let's break this down—two hours of regex101 and forum deep dives can be brutal, so I’m glad you asked. You need to target every . in your string that isn’t part of a word starting with @, right?

Here’s the regex that’ll do exactly what you need:

(?<!@[^\s]*)\.

Let’s unpack why this works:

  • (?<!@[^\s]*): This is a negative lookbehind assertion. It checks that the . we’re about to match is NOT preceded by an @ followed by any number of non-whitespace characters (aka the entire @-prefixed word, like @sys.any or @names). If the . is inside one of those @-words, this assertion fails, so the regex skips it.
  • \.: Escapes the dot character (since unescaped . matches any character in regex) to target only literal dots.

Testing this on your sample string:

this is @sys.any and. here @names hello. and good.bye

It will match exactly the dots you want:

  • The dot in and.
  • The dot in hello.
  • The first dot in good.bye

It will not match the dot in @sys.any because that’s part of an @-prefixed word.

A quick note: If you ever have @-words with multiple dots (like @user.first.last), this regex still works—it’ll ignore all dots inside those @-prefixed tokens automatically.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:33:52