E
eric.hall
Sorry for the newbie questions
I need a one-line regexp that only return a match if the test string
only exists once in the input. For example, find 'abc' if no other
occurrences of 'abc' exist anywhere in the input string of 'abc abc
abc'. This should be simple, but I'm having a lot of trouble with
limiting the scope.
/(?!(abc)).*abc.*/ doesn't work, because that traps the last instance
(which is not followed by anything). /.*abc.*(?<!(abc))/ has the same
problem in reverse. Adding them together for
/(?!(abc)).*abc.*(?<!(abc))/ traps 'bc abc ab' in the middle, which is
not what I want (I need to return a match only if it exists in
isolation).
This gets even harder if the input has lots of other noise in the
input. For example, 'abc def abc def abc'. Suffice it to say that my
input has lots of junk, including non-word characters.
I thought that something like this would be a fairly stock regexp but I
haven't been able to locate anything in google that seems relevant.
Surely this is possible?
Thanks for the help!
I need a one-line regexp that only return a match if the test string
only exists once in the input. For example, find 'abc' if no other
occurrences of 'abc' exist anywhere in the input string of 'abc abc
abc'. This should be simple, but I'm having a lot of trouble with
limiting the scope.
/(?!(abc)).*abc.*/ doesn't work, because that traps the last instance
(which is not followed by anything). /.*abc.*(?<!(abc))/ has the same
problem in reverse. Adding them together for
/(?!(abc)).*abc.*(?<!(abc))/ traps 'bc abc ab' in the middle, which is
not what I want (I need to return a match only if it exists in
isolation).
This gets even harder if the input has lots of other noise in the
input. For example, 'abc def abc def abc'. Suffice it to say that my
input has lots of junk, including non-word characters.
I thought that something like this would be a fairly stock regexp but I
haven't been able to locate anything in google that seems relevant.
Surely this is possible?
Thanks for the help!