I want to match a company name once from a string that looks like this
What I want: Distribution Services Management only once
What I get CATE-N LUNA SI-N STELE SRL
What I'm trying Client\n+(.*?[ ]\s)
I want to match a company name once from a string that looks like this
What I want: Distribution Services Management only once
What I get CATE-N LUNA SI-N STELE SRL
What I'm trying Client\n+(.*?[ ]\s)
This might help you:
Client\n{2}.*\s{5}(.*)
My Logic is:
Using \s could also match a newline, and in the example data it looks like there are 2 or more spaces before the part that you want to match.
The reason you get capture CATE-N LUNA SI-N STELE SRL in group 1 is because you start the match after the newline without matching the part after the 2 spaces.
You could use
\bClient\n+.*[^\S\r\n]{2}(\S.*)
In parts, the pattern matches
\bClient\n+.*[^\S\r\n]{2} Match until the end of the string, and backtrack to the last occurrence (or use \n+.*? for the first occurrence) of 2 whitespace chars except a newline(\S.*) Capture group 1, match at least a single non whitespace char followed by optional chars except a newlinetry this :
(?<= \b).*(?=\n CIF)
The way I solved this was to check the desired word between many spaces and the word CIF in the next line. I thought two spaces in (?<= \b) would be enough.
(?<= \b) part is to check at least two spaces and the word boundry. (?=\n CIF) part is positive lookahead assertion to check if it is before CIF in the next line.