Q:

python - regex parse numerical value to array without asterisk and space

I have sample data below I would like to extract the first two columns of numbers and put them in an array.
Data Set:
      54     1%    2.11 MB  52 min       0.0    49.0    0.0  test1 test1_4.1.6_Win_x86_install_en-US.tar
      55    17%   31.89 MB  1 min        0.0  1263.0    0.0  test344 base-2.10.6-x86_64.dmg
      56    17%   31.18 MB  1 min        0.0  1267.0    0.0  test2 base-2.10.4-x86_64.dmg
      57    15%   27.12 MB  2 min        0.0  1066.0    0.0  test23 base-2.10.6-setup.exe
      58    20%   32.16 MB  1 min        0.0  1196.0    0.0  test232 base-2.10.8-x86_64-2.dmg
      59*    0%       None  599 days     0.0     0.0    0.0  test12 base.1.2_Linux_x86_deb.tar.gz
      60    14%   26.31 MB  2 min        0.0  1243.0    0.0  test23 base-2.10.4-setup-2.exe
      61     0%       None  Unknown      0.0     0.0   None  Idle base-0.9.24.1.exe
    Sum:          150.8 MB               0.0  6084.0

Current Results:
    54     1
    55    17
    56    17
    57    15
    58    20
    60    14

Desired Results:
    54     1
    55    17
    56    17
    57    15
    58    20
    59    0
    60    14
    61     0

Problem:
Missing id 59 and 0
Although I have gotten it to capture the first two columns. I can't seem to capture that column with the asterisk 
I'm trying to see how to improve the "\s+" section of the regular expression to include the number and exclude the asterisk.
Code:
    import re

    output4a = """
      54     1%    2.11 MB  52 min       0.0    49.0    0.0  test1 test1_4.1.6_Win_x86_install_en-US.tar
      55    17%   31.89 MB  1 min        0.0  1263.0    0.0  test344 base-2.10.6-x86_64.dmg
      56    17%   31.18 MB  1 min        0.0  1267.0    0.0  test2 base-2.10.4-x86_64.dmg
      57    15%   27.12 MB  2 min        0.0  1066.0    0.0  test23 base-2.10.6-setup.exe
      58    20%   32.16 MB  1 min        0.0  1196.0    0.0  test232 base-2.10.8-x86_64-2.dmg
      59*    0%       None  599 days     0.0     0.0    0.0  test12 base.1.2_Linux_x86_deb.tar.gz
      60    14%   26.31 MB  2 min        0.0  1243.0    0.0  test23 base-2.10.4-setup-2.exe
      61     0%       None  Unknown      0.0     0.0   None  Idle base-0.9.24.1.exe
    Sum:          150.8 MB               0.0  6084.0"""

    idPercentage3 = re.findall(r'^\s+([0-9]+)\s+([0-9]+)', output4a, flags=re.MULTILINE)
    print (idPercentage3)

thanks

A:

I'd recommend ^\s*(\d+)\*?\s+(\d+), which makes the literal * character optional with ?. I've also made your first space run optional as well; it seems reasonable to allow the numbers to align with the beginning of the line without padding (but you can change * back to + if you wish). Lastly, \d is equivalent to [0-9].
Full code:
import re

output4a = """
  54     1%    2.11 MB  52 min       0.0    49.0    0.0  test1 test1_4.1.6_Win_x86_install_en-US.tar
  55    17%   31.89 MB  1 min        0.0  1263.0    0.0  test344 base-2.10.6-x86_64.dmg
  56    17%   31.18 MB  1 min        0.0  1267.0    0.0  test2 base-2.10.4-x86_64.dmg
  57    15%   27.12 MB  2 min        0.0  1066.0    0.0  test23 base-2.10.6-setup.exe
  58    20%   32.16 MB  1 min        0.0  1196.0    0.0  test232 base-2.10.8-x86_64-2.dmg
  59*    0%       None  599 days     0.0     0.0    0.0  test12 base.1.2_Linux_x86_deb.tar.gz
  60    14%   26.31 MB  2 min        0.0  1243.0    0.0  test23 base-2.10.4-setup-2.exe
  61     0%       None  Unknown      0.0     0.0   None  Idle base-0.9.24.1.exe
Sum:          150.8 MB               0.0  6084.0"""

id_percentage3 = re.findall(
    r'^\s*(\d+)\*?\s+(\d+)', 
    output4a, flags=re.MULTILINE
)

for a, b in id_percentage3:
    print(a, b)

Output:
54 1
55 17
56 17
57 15
58 20
59 0
60 14
61 0

