Reputation: 627
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...
Upvotes: 2
Views: 767
Reputation: 43169
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.
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.
Upvotes: 1