Match the row before or after a match?

Hello guys, anyone can help me with an regular expression which can select the line before an match.
For example in this text I need to take the age “53” but sometimes is above and sometimes is after the “Age & Sex:” string.

Patient Name: Michael
53
Age & Sex:
M/F
Date of Use or

Any Ideas? Thanks you!

hey @Ionut_Frincu
You could use /d{2} to get 2 numbers for the age.
However the digits might come from the date portion also but you could extract the first part by:-
regex.fisrt()
regex - your regex var name
hope it helps

Hello nv08, thank you for reply, but it’s not working… I tried also with \d{2} and it take all the numbers that have minim 2 digits.

may i know apart ftom age which of the field have digits?

@Ionut_Frincu - Please try below… this simple pattern covers both the cases…but if you have any other digits in your string then shown pattern wont work…

OR below is the other option, where it will look for specific word in the next line and matches

image

3rd one, you can see it didn’t match the 53

Thank you @prasath17 ,the second solution was working.
Cheers!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.