0

i want to take only mail address which not contains 'xxx-' at the start and '@test.com' at the end of the mail string.

Here my code :

->where('email', 'regexp', "/^((?!@test.com).)*$/i")

Here i take only email where not contains 'test.com' at the end. I want to not take email where the start is 'xxx-' too. Anyone know how to do this ? Thank you !

Tony S
  • 363
  • 1
  • 13

1 Answers1

2

You may use this regex with 2 negative lookahead assertions (rules):

^(?!xxx-)(?![^@]+@test\.com$)[^@]+@[^@]+$

RegEx Demo

RegEx Details:

  • ^: Start
  • (?!xxx-): Don't allow email to start with xxx-
  • (?![^@]+@test\.com$): Don't allow email to end with test.com
  • [^@]+@[^@]+: Match an email that must have only one @
  • $: End
anubhava
  • 664,788
  • 59
  • 469
  • 547
  • 1
    Looks like it's not matching the first example there, you'll want to accept any characters between those two lookahead assertions: `^(?!xxx-).+(?!@test\.com$)` https://regex101.com/r/3mET7i/2 – rbonestell Feb 14 '20 at 17:16
  • 1
    It is matching first one already. See `1 match` in green in my demo. It is not highlighted because of zero width. Change it to `^(?!xxx-)(?!@test\.com$).+` – anubhava Feb 14 '20 at 17:18