1

I have a regex that does not allow an url to start with http, and foreces it to start with www. Now I would like to add to it so it does not allow any special characters.

Current regex: ^(?!https?)www\..*$

Characters I do not want to allow: !"@#£¤$%&/{([)]=}?+`´*'

I'm using ASP.NET.

I've tried using negated characters for ex: [^%!] to not allow % and !, but can't get it to work, it just checks the first character of the word.

1 Answer 1

2

Use a negative lookahead assertion at the start which includes the list of characters you want to exclude.

^(?!.*?[!"@#£¤$%&\/{(\[)\]=}?+\\`´*'])(?!https?)www\..*$
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you for taking the time to answer. However in regex101.com this does not let me write for example "www.test.com"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.