2

String to search for = "in relation to Company A"

Document Contain two lines

(a) in relation to Company A, 31 December 2025;
(b) in relation to Company A, Company B, Company C is 31 December 2025;

Regex which im trying = "(?<=in relation to Company A)(.*)"

But this gives me both lines, I only need first line:

Output Required (means extracting point (a)):

31 December 2025

I'm struggling with changing regex so that i add date part after the word...

2
  • 1
    Several expressions might help, e.g. in relation to Company A,\s*(\d+.+), this requires at least one digit after your needle. Commented Oct 26, 2018 at 15:13
  • @Jan - can you add this as answer as it worked for me... Commented Oct 26, 2018 at 15:19

1 Answer 1

1

For your given examples you could use

in relation to Company A,\s*(\d+[^\n\;]+)

and take the first group, see the demo on regex101.com.


This means

in relation to Company A, # "in relation to Company A," literally
\s*                       # 0+ whitespaces
(\d+[^\n\;]+)             # at least one digit + not a newline nor a semicolon

In the end use the first group in your programming language/tool.

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.