0

I have below string:

<Total Slots :>
        <8 (4-channel per CPU, 8 DIMM per CPU)>
    <Capacity :>
        <Maximum up to 1024GB RDIMM>
    <Memory Type :>
        <fd4 2933/2666/2400 /2133  RDIMM
        bbh567 2933/2666/2400 /2133  LRDIMM>
    <screen :>
        <720>
    <color :>
        <blue>
    <Memory Quality :>
        <Certain 3452345tte  READ
        Non certain 7JJEN232  LREAD>

I want memory data (multiple captures) within Memory Type and Memory Quality like this:

Memory Type
Capture 1: 2933/2666/2400 /2133
Capture 2: 2933/2666/2400 /2133

Memory Quality
Capture 1: 3452345tte
Capture 2: 7JJEN232

If I use regex: Memory Type[\s\S]+?<(.+?)>, it returns:

screen :

If I use regex: Memory Type[\s\S]+?<([\s\S]+?)>, it returns:

fd4 2933/2666/2400 /2133  RDIMM
        bbh567 2933/2666/2400 /2133  LRDIMM

I don't understand how do I create a regex that first captures the Memory tag and then then the middle data.

I am using Python. Thank you.

  • 1
    Regex is likely not the correct tool here. https://stackoverflow.com/questions/7553722/when-should-i-not-use-regular-expressions – lwileczek Oct 22 '20 at 01:37

1 Answers1

0

Regular expressions are likely not what you are looking for. Regex is used to parse normal language, like a tweet or newspaper. However, assuming a lot about your inputs and outputs here, you could use something like this: regex101

r"(?P<mem_type>\d{4}/\d{4}/\d{4}\s/\d{4})\s+L?RDIMM|(certain\s(?P<mem_quality>\w+))"

With the case insensitive flag. This will produce named groups in python that you can pull out. Not sure if a parser exists or if you want to take the time to write one.

lwileczek
  • 2,084
  • 18
  • 27