<p>您的<code>(?<=subject)(.{30}(?:\s|.))</code>正则表达式在<code>subject</code>之后声明位置。然后抓取除换行符以外的30个字符,然后匹配空白或除换行符以外的任何字符。这并不真正符合您的要求,因为子字符串可以是任何长度。</p>
<p>您可以将基于交替的正则表达式与捕获组一起使用:</p>
<pre><code>subject:\s*([^.]+|\S+)
</code></pre>
<p>见<a href="https://regex101.com/r/aC3pC1/1" rel="nofollow">regex demo</a></p>
<p><strong>详细信息</strong>:</p>
<ul>
<li><code>subject:</code>-文本<code>subject:</code>字符串</li>
<li><code>\s*</code>-0+空格</li>
<li><code>([^.]+|\S+)</code>组1捕获1个或多个非周期符号或1+非空白符号</li>
</ul>
<p><strong>注意:<code>[^.]+</code>与空格匹配,<code>\S+</code>与空格不匹配,^{<em>的顺序在这里很重要。如果<code>\s*</code>之后的子字符串以点开头,则<code>\S+</code>将匹配该子字符串,直到出现空白。</p>
<p><a href="https://ideone.com/JRe3y9" rel="nofollow">Python demo</a>:</p>
<pre><code>import re
p = re.compile(r'subject:\s*([^.]+|\S+)', re.IGNORECASE)
s = "Features: -Includes hanging accessories. -Artist: William-Adolphe Bouguereau. -Made with 100pct cotton canvas. -100pct Anti-shrink pine wood bars and Epson anti-fade ultra chrome inks. -100pct Hand-made and inspected in the U.S.A. -Orientation: Horizontal. **Subject: -Figures/Nautical and beach.** Gender: -Unisex/Both. Size: -Mini 17'' and under/Small 18''-24''/Medium 25''-32''/Large 33''-40''/Oversized 41'' and above. Style: -Fine art. Color: -Blue. Country of Manufacture: -United States. Product Type: -Print of painting. Region: -Europe. Primary Art Material: -Canvas. Dimensions: -8'' H x 12'' W x 0.75'' D: 0.72 lb. -12'' H x 18'' W x 0.75'' D: 1.14 lbs. -12'' H x 18'' W x 1.5'' D: 2.45 lbs. -18'' H x 26'' W x 0.75'' D: 1.44 lbs. Paintings Prints Tori White Wildon Photography Photos Posters Abstract Black D cor Designs Framed Hazelwood Hokku Home Landscape Oil Accent 075 12 15 18 26 40 60 8 D H W x 1 1017 1824 2532 holidays, christmas gift gifts for girls boys"
m = p.search(s)
if m:
print(m.group()) # this includes Subject:
print(m.group(1)) # this does not include Subject:
</code></pre>