Forum Discussion

PerBonomi's avatar
5 years ago

RegEx only partially working

Hi folks. Question.

I have pretty standard regex in place to filter emails, but it only works sometimes.

Say I want to filter bonomi @ spotify.com.

These are my results:

Submitted Post:
bonomi @ spotify.com
bonomi @ spotify.com

Result:
*bleep*
*bleep*

Submitted post:
bonomi @ spotify.com
bonomi@spotify.com

Result:
*bleep*
*bleep* 

Submitted post:
bonomi@spotify.com
bonomi@anything.random
bonomi @ spotify.com
anyone@anydomain.net
Result:
**bleep**spotify.com
**bleep**anything.random
bonomi @ spotify.com
**bleep**

And therein lies the problem. Why is the same email filtered out on line 1 in previous posts, but not on line 3 in the last one? Do I need some kind of check for paragraph? I'd expect that not to matter?

 

The RegEx I'm using:

[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*(\s)*(@|(\s@\s)+)+(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?((\s)*\.(\s)*))+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?
  • Do you have any other rules that would match bonomi? I know it's a long shot but I get something similar with other rules winning?

     

  • I've tested your regex, and all tested strings were blocked. I'm wondering if you may have another regex that could interfere.

    Also, not sure if related, but regex101 reports an error. After fixing it, all the strings are blocked in regex101, but throw an error in the community.