0

I have a string (without doble qoutes) "2022-12-15 21:23:22 - a123456 (Remarks) 2022-12-15 22:12:22 - a123456 (Remarks) User acknowledgement time"

There are 2 date/time stamps in this string in need the date/time stamp appearing before User acknowledgement time. I am using regex (\.*\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}.*User acknowledgement time) my regex is capturing very first time stamp showing up in string but I need date/time stamp right before User acknowledgement time. Please help.

(\.*\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}.*User acknowledgement time)

I am expecting result as 2022-12-15 22:12:22 - a123456 (Remarks) User acknowledgement time

but I am getting result 2022-12-15 21:23:22 - a123456 (Remarks) User acknowledgement time

Mkh
  • 1
  • Why not just demand another date in your RegEx? As is, it's picking the first one it finds, and the 2nd gets lost with the wildcard – johnjps111 Oct 25 '22 at 18:35
  • @johnjps111. Thanks, it helped to do similar and got more results. – Mkh Oct 26 '22 at 16:05

1 Answers1

0

I think your group just needs to move. Group 1 is what you are after:

.*(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}).*User acknowledgement time

regex101

Gary_W
  • 9,933
  • 1
  • 22
  • 40
  • I tried making 2 groups but still in first group I am getting date showing in beginning of the string not the one i need which is before User acknowledgement time – Mkh Oct 25 '22 at 18:58