擅长:python、mysql、java
<p>您正在寻找单词边界,如果我理解正确,逗号之间的所有内容:</p>
<pre><code>[^,]+?W\b
</code></pre>
<ul>
<li>一切都不是逗号,懒惰</li>
<li>文字大写<code>W</code>,后跟单词边界<code>\b</code></li>
</ul>
<p><a href="https://regex101.com/r/nUY4lx/1" rel="nofollow noreferrer">Online Demo</a>,
代码示例:</p>
<pre><code>import re
regex = r"[^,]+?W\b"
test_str = ("text = \"Fast charging 25W, USB Power Delivery 3.0, Fast Qi/PMA wireless charging 12W, Reverse wireless charging 4.5W\"\n")
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
</code></pre>