0

I have the following string

.....text .....person id: 2938 date of birth......text ....  
.....................person id: 238949 date of birth........
.......person id: 5555 date of birth..........................
...........person id: 232229 date of birth........

I need to get the substring that appears between the third occurence of the work person id and date of birth, i.e. 5555

How can I parse it?

1
  • where's your attempt? Commented Oct 12, 2013 at 3:31

1 Answer 1

2

You could do something like this:

(?:person id:.*?){3}(\d+)\s+date of birth

This will match:

  • person id: followed by zero or more characters, non-greedily, repeated 3 times
  • one or more digits, captured in group 1
  • one or more whitespace characters
  • date of birth

Of course, if there are many such occurrences like this (say 6 such similar records) it will actually match the number every third occurrence of person id:.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.