Regex 如何仅使用正则表达式提取列表项?

Regex 如何仅使用正则表达式提取列表项?,regex,Regex,我正在创建一个正则表达式,以从如下文本中提取列表项: Blab bla bla 1. Extract files there. 2. Install using rights permissions. 3. Copy some files from binary directory located in Program files or you can change the location. 4. Test the software. Blabla 我使用

我正在创建一个正则表达式,以从如下文本中提取列表项:

  Blab bla bla
  1. Extract files there.
  2. Install using rights permissions.
  3. Copy some files from binary directory located in Program files
     or you can change the location.
  4. Test the software.

  Blabla
我使用的正则表达式类似于:
(\d+)\.\s(.*)
,但不使用
3中的第二行。

如何做到这一点

我只想

  1. Extract files there.
  2. Install using rights permissions.
  3. Copy some files from binary directory located in Program files
     or you can change the location.
  4. Test the software.
您可以使用
(?:\d+)\。\s(?:(.*)(?:\n{3,}(.*)?)
。这假定任何其他行都将以3个或更多空格()开头。Python中的示例:

>>> p = re.compile(r"(?:\d+)\.\s(?:(.*)(?:\n {3,}(.*))?)")
>>> p.findall(text)
[('Extract files there.', ''),
 ('Install using rights permissions.', ''),
 ('Copy some files from binary directory located in Program files',
  'or you can change the location.'),
 ('Test the software.', '')]
您可以使用
(?:\d+)\。\s(?:(.*)(?:\n{3,}(.*)?)
。这假定任何其他行都将以3个或更多空格()开头。Python中的示例:

>>> p = re.compile(r"(?:\d+)\.\s(?:(.*)(?:\n {3,}(.*))?)")
>>> p.findall(text)
[('Extract files there.', ''),
 ('Install using rights permissions.', ''),
 ('Copy some files from binary directory located in Program files',
  'or you can change the location.'),
 ('Test the software.', '')]

是要获取整个块还是单独获取每个项?压痕总是这样吗?以及块下方的空行?如何表示一行是列表的一部分而不是
blabla
的一部分?因为列表和下面的文本之间有一个额外的换行符?整个应该可以,下面有一些3-4个空格标识。您是要获取整个块还是单独获取每个项?压痕总是这样吗?以及块下方的空行?如何表示一行是列表的一部分而不是
blabla
的一部分?因为列表和下面的文本之间有一个额外的换行符?整个应该可以,下面有一些3-4空格标识