in reply to Regex matching a string beginning with "root: " but not containing another string

Use a negative lookahead assertion:

@data = split(/\n/, <<'__EOI__'); root: myself@domain.of-my.own anotherone: myself@domain.of-my.own root: yetanother1@domain.of-my.own __EOI__ $email = 'myself@domain.of-my.own'; foreach (@data) { /^root: (?!\Q$email\E)(\S+)/ && print("$1\n"); } __END__ output ====== yetanother1@domain.of-my.own
  • Comment on Re: Regex matching a string beginning with "root: " but not containing another string
  • Download Code