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

技术需求:匹配9位数字且其后不紧跟&符号的正则表达式

Solution for Matching 9-Digit Numbers (Excluding Those Followed by &)

Got it, let's work through this regex problem. You want to target 9-digit sequences, but skip any that are immediately followed by an ampersand (&). Here's the regex that does exactly that:

\b\d{9}(?!&)\b

Breakdown of the Regex:

  • \d{9}: The core part—matches any sequence of exactly 9 digits.
  • (?!&): This is a negative lookahead assertion. It checks that the position right after the 9 digits does NOT have an ampersand. If there's a & immediately following, the match fails.
  • \b: Word boundaries ensure we don't accidentally match a 9-digit segment inside a longer number (like the first 9 digits of 1234567890). This keeps our matches limited to standalone 9-digit numbers, which aligns with your examples.

Test Cases:

  • Matches: randomText123456789RandomText → Captures 123456789
  • No Match: randomText123456789&RandomText → No results returned, since the 9 digits are followed by &

If your use case involves 9-digit numbers adjacent to non-word characters (like underscores or special symbols), you can tweak the word boundaries to something more specific, but for the examples you provided, this regex works perfectly.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 09:52:33