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

正则表达式匹配异常:无匹配结果,求提取目标内容的正确表达式

Solution for Your Regex Extraction Need

Got it, let's work through this regex problem step by step. Your goal is to capture everything from the start marker :[]: up to and including the first colon that comes after it—here are two reliable ways to do this:

Option 1: Non-Greedy Matching (Simple & Readable)

Use this regex pattern:

:[]:\s*.*?:

Breakdown:

  • :[]:: Explicitly matches your fixed starting marker.
  • \s*: Matches any number of whitespace characters (including zero) right after the marker, handling cases where there's no space or multiple spaces.
  • .*?: The non-greedy version of .*—it matches any characters but stops at the first occurrence of the next part of the pattern.
  • :: Matches the first colon that follows the marker, which is our stopping point.

Option 2: Exclusion Character Set (More Efficient)

If you want a pattern that avoids regex backtracking (better for large documents), use this instead:

:[]:\s*[^:]+:

Breakdown:

  • :[]: & \s*: Same as above—matches the start marker and any leading whitespace.
  • [^:]+: Matches one or more characters that are NOT colons. This directly stops at the first colon, no need for non-greedy logic.
  • :: Matches the closing colon we want to include.

Why Your Previous Patterns Failed:

  • Your first pattern \B:\[\]:.*:\B used .*, which is greedy—it matches as much as possible, so it would run all the way to the last colon in the section instead of the first.
  • Your second pattern \B:\[\]:\s*.:{1} only matches a single character after the whitespace (the .), which is why it didn't find matches for longer text like Abet1, Abetted34.

Test with Your Examples:

For your first sample line:

:[]: Abet1, Abetted34: Find the usage in table under section 1-CB-45: Or more info from the related section starting with PARTIE-DU-CORPS.

Both patterns will correctly capture: :[]: Abet1, Abetted34:

For your second sample line:

:[]: Ou est-ce que tu a mal: Tu as mal aux jambes: Find usage in section 145-TT-LA-TETE.

They'll capture: :[]: Ou est-ce que tu a mal:

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 13:23:13