没有得到所有匹配项
re not getting all matches
我在从以下字符串中提取文本时遇到一些问题:
'Amount\n2144-PL\n1XL 2XL 3XL\n2144-\nPL Navy Blue 2 2 2 6 .50 .00\nETK-2097K-PL PLUS-TOP -
BACK BUTTON TUNICS 95% RAYON 5% SPANDEX MADE IN USA\n1XL 2XL 3XL\nBlack 2 2 2 6 .00 .00\nTeal
2 2 2 6 .00 .00\nETK-2197-SW-\n1XL 2XL 3XL\nPL ETK-\n2197- H.Grey/Burgu… 2 2 2 6 .00
.00\nOff-White/Black 1 1 1 3 .00 .00\nETK-2143 Tops - 95% RAYON 5% SPANDEX MADE IN USA\nS M
L\nHeather Grey 2 2 2 6 .50 .00\nRoyal Blue 2 2 2 6 .50 .00\nRuby Red 2 2 2 6 .50
.00\nETK2186-GD- Tops-Stripe Solid-95% Rayon 5% Spandex Made in USA\nPL\n1XL 2XL
3XL\nBurgundy/Bur… 2 2 2 6 .00 .00\nIvory/Black 2 2 2 6 .00 .00\n2139 - WP-PL PLUS TOP
-95% RAYON 5% SPANDEX MADE IN USA\n1XL 2XL 3XL\nAs Shown 2 2 2 6 .50 .00\nETK-2228\nS M L\nETK-
\n2228 Off-White/Black 2 2 2 6 .50 .00\nETK-2149-PL\n1XL 2XL 3XL\nETK-\n2149- Taupe 2 2 2 6
.50 .00\nBACK\nORDERED\nWhite 2 2 2 6 .50 .00\nSub'
我正在寻找 \nOff-White/Black 1 1 1 3 .00 .00\n
模式来获取字符串中的所有项目,但由于某种原因,我没有获得与以下正则表达式的所有匹配项:
item_quantity_price = re.compile(r"\n[A-Za-z0-9-_./\s]*\d[\s]\d[\s]\d[\s]\d[\s][$]\d\d\d?.\d{2}[\s]
[$]\d\d\d?.\d{2}\n")
如有任何信息,我们将不胜感激。
此致。
编辑:
使用:\n[A-Za-z0-9-_./\s]*(?:\s\d+){4}\s$\d+.\d+\s$\d+.\d+\n
结果:
click
使用
item_quantity_price = re.compile(r'^[\w\s./-]*(?:\s\d+){4}(?:\s$\d+\.\d+){2}$', re.M | re.A)
参见 proof。使用 re.A
\w
等于 [A-Za-z0-9_]
并且您可以缩短表达式。
说明
--------------------------------------------------------------------------------
^ the beginning of the line
--------------------------------------------------------------------------------
[\w\s./-]* any character of: word characters (a-z, A-
Z, 0-9, _), whitespace (\n, \r, \t, \f,
and " "), '.', '/', '-' (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
(?: group, but do not capture (4 times):
--------------------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
){4} end of grouping
--------------------------------------------------------------------------------
(?: group, but do not capture (2 times):
--------------------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
--------------------------------------------------------------------------------
$ '$'
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
\. '.'
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
){2} end of grouping
--------------------------------------------------------------------------------
$ the end of the line
我在从以下字符串中提取文本时遇到一些问题:
'Amount\n2144-PL\n1XL 2XL 3XL\n2144-\nPL Navy Blue 2 2 2 6 .50 .00\nETK-2097K-PL PLUS-TOP -
BACK BUTTON TUNICS 95% RAYON 5% SPANDEX MADE IN USA\n1XL 2XL 3XL\nBlack 2 2 2 6 .00 .00\nTeal
2 2 2 6 .00 .00\nETK-2197-SW-\n1XL 2XL 3XL\nPL ETK-\n2197- H.Grey/Burgu… 2 2 2 6 .00
.00\nOff-White/Black 1 1 1 3 .00 .00\nETK-2143 Tops - 95% RAYON 5% SPANDEX MADE IN USA\nS M
L\nHeather Grey 2 2 2 6 .50 .00\nRoyal Blue 2 2 2 6 .50 .00\nRuby Red 2 2 2 6 .50
.00\nETK2186-GD- Tops-Stripe Solid-95% Rayon 5% Spandex Made in USA\nPL\n1XL 2XL
3XL\nBurgundy/Bur… 2 2 2 6 .00 .00\nIvory/Black 2 2 2 6 .00 .00\n2139 - WP-PL PLUS TOP
-95% RAYON 5% SPANDEX MADE IN USA\n1XL 2XL 3XL\nAs Shown 2 2 2 6 .50 .00\nETK-2228\nS M L\nETK-
\n2228 Off-White/Black 2 2 2 6 .50 .00\nETK-2149-PL\n1XL 2XL 3XL\nETK-\n2149- Taupe 2 2 2 6
.50 .00\nBACK\nORDERED\nWhite 2 2 2 6 .50 .00\nSub'
我正在寻找 \nOff-White/Black 1 1 1 3 .00 .00\n
模式来获取字符串中的所有项目,但由于某种原因,我没有获得与以下正则表达式的所有匹配项:
item_quantity_price = re.compile(r"\n[A-Za-z0-9-_./\s]*\d[\s]\d[\s]\d[\s]\d[\s][$]\d\d\d?.\d{2}[\s]
[$]\d\d\d?.\d{2}\n")
如有任何信息,我们将不胜感激。
此致。
编辑:
使用:\n[A-Za-z0-9-_./\s]*(?:\s\d+){4}\s$\d+.\d+\s$\d+.\d+\n
结果: click
使用
item_quantity_price = re.compile(r'^[\w\s./-]*(?:\s\d+){4}(?:\s$\d+\.\d+){2}$', re.M | re.A)
参见 proof。使用 re.A
\w
等于 [A-Za-z0-9_]
并且您可以缩短表达式。
说明
--------------------------------------------------------------------------------
^ the beginning of the line
--------------------------------------------------------------------------------
[\w\s./-]* any character of: word characters (a-z, A-
Z, 0-9, _), whitespace (\n, \r, \t, \f,
and " "), '.', '/', '-' (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
(?: group, but do not capture (4 times):
--------------------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
){4} end of grouping
--------------------------------------------------------------------------------
(?: group, but do not capture (2 times):
--------------------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
--------------------------------------------------------------------------------
$ '$'
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
\. '.'
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
){2} end of grouping
--------------------------------------------------------------------------------
$ the end of the line