<h2>说明</h2>
<p>我建议使用以下正则表达式来查找和替换您不感兴趣的子字符串。通过说明度量单位,这也将处理不缩写的度量单位。在</p>
<p><code>\s*(?:(?:(?:[0-9]\s*)?[0-9]+\/)?[0-9]+\s*(?:(?:c\.|cups?|tsp\.|teaspoon|tbsp\.|tablespoon)\s*)?)|,.*|.*\bor\b</code></p>
<p><img src="https://www.debuggex.com/i/39pRyumMhJd1Z_HV.png" alt="Regular expression visualization"/></p>
<p><strong>替换为:</strong>无</p>
<h2>示例</h2>
<p><strong>现场演示</strong></p>
<p>显示如何匹配</p>
<p><a href="https://regex101.com/r/qV5iR8/3" rel="nofollow">https://regex101.com/r/qV5iR8/3</a></p>
<p><strong>示例字符串</strong></p>
<p>注意,最后一行有一个<code>or</code>分隔的双成分,根据他们希望消除第一个成分的OP。在</p>
<pre><code>1 medium tomato, cut into 8 wedges
4 c. torn mixed salad greens
1/2 small red onion, sliced and separated into rings
1/4 small cucumber, sliced
1 1/4 c. sliced pitted ripe olives
2 Tbsp. reduced-calorie Italian salad dressing
2 Tbsp. lemon juice
1 Tbsp. water
1/2 tsp. dried mint, crushed
1/4 c. crumbled Feta cheese or 2 Tbsp. crumbled Blue cheese
</code></pre>
<p><strong>更换后</strong></p>
^{pr2}$
<h2>解释</h2>
<pre><code>NODE EXPLANATION
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
(?: group, but do not capture:
(?: group, but do not capture (optional
(matching the most amount possible)):
(?: group, but do not capture (optional
(matching the most amount possible)):
[0-9] any character of: '0' to '9'
\s* whitespace (\n, \r, \t, \f, and " ")
(0 or more times (matching the most
amount possible))
)? end of grouping
[0-9]+ any character of: '0' to '9' (1 or
more times (matching the most amount
possible))
\/ '/'
)? end of grouping
[0-9]+ any character of: '0' to '9' (1 or more
times (matching the most amount
possible))
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
(?: group, but do not capture (optional
(matching the most amount possible)):
(?: group, but do not capture:
c 'c'
\. '.'
| OR
cup 'cup'
s? 's' (optional (matching the most
amount possible))
| OR
tsp 'tsp'
\. '.'
| OR
teaspoon 'teaspoon'
| OR
tbsp 'tbsp'
\. '.'
| OR
tablespoon 'tablespoon'
) end of grouping
\s* whitespace (\n, \r, \t, \f, and " ")
(0 or more times (matching the most
amount possible))
)? end of grouping
) end of grouping
| OR
, ','
.* any character except \n (0 or more times
(matching the most amount possible))
| OR
.* any character except \n (0 or more times
(matching the most amount possible))
\b the boundary between a word char (\w) and
something that is not a word char
or 'or'
\b the boundary between a word char (\w) and
something that is not a word char
</code></pre>