0

I'm trying to filter every string which are not valid (simple) email adress. Thus starting with a dot is a "no go".

But my expression doesn't reject strings like .test@test.be

preg_match('/^(?<!\.)[\w0-9\.]+(?<!\.)@+(?<!\.)[\w0-9\.]+\.\w{1,3}(\s*<[^>]+>)?$/', $part)

Shouldn't /^(?<!\.) do the trick?

EDIT: This question is not a duplicate of the indicated question.

I am not asking about the context, I want more information about look behind, the approach itself, not the specific use-case.

Chris Baker
  • 49,926
  • 12
  • 96
  • 115
Serge Profafilecebook
  • 1,165
  • 1
  • 14
  • 32

1 Answers1

0

It turns out its look-ahead counterpart (^(?!\.)) does the trick instead: https://regex101.com/r/zZ8yT7/1

Dmitry Egorov
  • 9,542
  • 3
  • 22
  • 40