Search code examples
regexemailwebaddress

How do I check for a web address and reject an email with regex?


Where I'm running into a roadblock is trying to check for this

(?<http>(http|ftp|https):\/\/)?(?<address>([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?)

while rejecting the expression if it contains the @ sign.

I've tried a number of variations on this with no success.

What would work is if I can tell it to make sure that there are no @ characters in it but I don't want to require a character using the [^@] syntax. So how do I tell regex to accept \w and reject @ at the same time. I can't do [\w^@] to the best of my knowledge.

My Difficulty is that I'm using regex replace. Ar you suggesting then that I use a placeholder and ten match against that afterwards?


Solution

  • You don't have to get everything into one regex. You could for example, match against your existing regex, then check with a secondary regex that the string doesn't have an @-sign.