Hello, @barry-payne and All,
Sorry to discuss about an already solved problem but I do think that your regex ^A.*110M00104(?!.*110M00104$) could be simply written :
^A.*110M00104
Indeed, given your text, these two regexes give the same results : all lines from A0000 till 110M00104 are matched !
A0000059700000001 000000012016101020161010NLEE 4 110M00104 DL2 Cross Roller Monthly PM
A0000059700000001 000000012016101020161010NLEE 4 110M00104
A0000059700000001 000000012016101020161010NLEE 4 110M00104 SAFETY FIRST- USE LOCK OUT/TAG OUT PRIOR
A0000059700000001 000000012016101020161010NLEE 4 110M00104 TO DOING THIS JOB
A0000059700000001 000000012016101020161010NLEE 4 110M00104
A0000059700000001 000000012016101020161010NLEE 4 110M00104 Determine what energy sources will be
A0000059700000001 000000012016101020161010NLEE 4 110M00104 locked out. (Electrical, Gas, Pneumatic,
A0000059700000001 000000012016101020161010NLEE 4 110M00104 Hydraulic, Steam, Etc#)
A0000059700000001 000000012016101020161010NLEE 4 110M00104
A0000059700000001 000000012016101020161010NLEE 4 110M00104 IF YOU ARE NOT SURE WITH THE ABOVE- SEE
A0000059700000001 000000012016101020161010NLEE 4 110M00104 SUPERVISOR IMMEDIATELLY
In your text, the string 110M00104 occurs once per line. So, once the first part ^A.*110M00104 has been matched, the negative look-ahead (?!.*110M00104$) is always true, because no more string 110M00104 occurs at the end of line !
Even if we change the last line, in such a way :
A0000059700000001 000000012016101020161010NLEE 4 110M00104 110M00104 SUPERVISOR IMMEDIATELLY
Either, the regex ^A.*110M00104 or your regex ^A.*110M00104(?!.*110M00104$), would match the string A0000059700000001 000000012016101020161010NLEE 4 110M00104 110M00104
If you, really, want to match a specific string ( for instance the string ABCD ) with the condition that no other string ABCD occurs, further on, in the same line, you should use the negative look-ahead (?!.*ABCD.*ABCD), evaluated, at beginning of the current line !
So, given the simple example text below :
A000 Line 1 12345 ABCD Some text after
A000 Line 2 12345 ABCD ABCD
A000 Line 3 12345 ABCD
A000 Line 4 12345 ABCD ABCD Test
The 3 regexes, below, do not match the lines 2 and 4 , which contain the string ABCD, twice :-)
^(?!.*ABCD.*ABCD)A.*ABCD matches between A000 and the unique occurrence of ABCD ( Line 1 and 3 )
^(?!.*ABCD.*ABCD)A.*ABCD(?=.) matches between A000 and the unique occurrence of ABCD, which does not end the line ( Line 1, only )
^(?!.*ABCD.*ABCD)A.*ABCD(?=\R) matches between A000 and the unique occurrence of ABCD, which ends the line ( Line 3, only )
Of course, the four regexes, below, without the look-ahead, consider all the lines and, moreover :
^A.*ABCD matches between A000 and the last occurrence of the string ABCD ( Line 1 to 4 )
^A.*?ABCD matches between A000 and the first occurrence of the string ABCD ( Line 1 to 4 )
^A.*ABCD(?=.) matches between A000 and an occurrence of ABCD, which does not end the line ( Lines 1, 2 and 4 )
^A.*ABCD(?=\R) matches between A000 and an occurrence of ABCD, which ends the line ( Lines 2 and 3 )
Best Regards,
guy038
P.S. :
I forgot to mention that the . matches newline option must be UNTICKED, of course !