Home > OS >  Regex to process multiple entries for a digital signature
Regex to process multiple entries for a digital signature

Time:04-14

I have the regex and corresponding match output here : https://regexr.com/6jiei

Which matches IP and time stamp for all entries currently but I also want the hexadecimal value for identification.

For ex for below Input string:

IDVal 4273E6D162ED2717A1CF4207A254004CD3F5307B
Posted 2022-12-28 07:35:55
Status 2022-12-28 08:10:11
Entry 94.62.86.22 2022-12-28 11:10:30
Entry 21.12.26.23 2022-12-28 13:10:30
Entry 113.132.26.203 2022-12-28 12:56:30
Entry 31.12.27.22 2022-12-28 12:35:30

Output should match/capture :

4273E6D162ED2717A1CF4207A254004CD3F5307B
94.62.86.22 2022-12-28 11:10:30
21.12.26.23 2022-12-28 13:10:30
113.132.26.203 2022-12-28 12:56:30
31.12.27.22 2022-12-28 12:35:30

I tried this regex :

(?s)(\b[A-F\d]{40}\b).*?(\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b).?(\b\d{4}(-\d{2}){2} (\d{2}:){2}\d{2}\b)

It then returns the hexadecimal digital signature, but then it only returns the first Entry and doesn't returns all the corresponding entries.

CodePudding user response:

You can start building your query from the back.

Case 1: 4273E6D162ED2717A1CF4207A254004CD3F5307B from the back match:

  • multiple alphanumerical characters of length 3 (3 otherwise will match seconds of next rows): [\d\w]{3}[\d\w]

Case 2: 113.132.26.203 2022-12-28 12:56:30 from the back match:

  • a set of numbers and ":": [\d:] ,
  • a space,
  • a set of numbers and "-": [\d-]
  • a space,
  • a set of numbers and ".": [\d\.]

Final regex:

"([\d\w]{3}[\d\w] |[\d\.]  [\d-]  [\d:] )$"

Tested on: https://regex101.com/

Does it work for you?

  • Related