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

时间:2017-11-21 11:31:01

标签: regex

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

var colorWidth = colorFrame.FrameDescription.Width;
var colorHeight = colorFrame.FrameDescription.Height;

// Assuming BGRA format here
byte[] pixels = new byte[colorWidth * colorHeight * 4];
colorFrame.CopyFrameDataToArray(pixels);

byte[] bgraPoints = new byte[depthWidth * depthHeight * 4];

for (var index = 0; index < depthData.Length; index++)
{
    var u = colorpoints[index].X;
    var v = colorpoints[index].Y;
    if (u < 0 || u >= colorWidth || v < 0 || v >= colorHeight) continue;
    var pixelsBaseIndex = v * colorWidth + u;
    Array.Copy(pixels, 4 * pixelsBaseIndex, bgraPoints, 4 * index, 4);
}

var index = 0;
var red = bgraPoints[4 * index + 2];
var green = bgraPoints[4 * index + 1];
var blue = bgraPoints[4 * index];

我使用了正则表达式: 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 个答案:

答案 0 :(得分:0)

您可以使用(?:\d+)\.\s(?:(.*)(?:\n {3,}(.*))?)。这假设任何其他行将以3个或更多空格(online demo)开头。 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.', '')]