1

I have this Regex

^(?!.*\b(?:https?:\/\/|www\.))\w+(?:\.\w+)*\.\w{2,}(?:,\w+(?:\.\w+)*\.\w{2,})+$

that captures multiple URL separated by commas caputres google.com,facebook.com but not with extra characters like google.com/home.php?,facebook.com/pages/#ref=?

1 Answer 1

2

Assuming your URLs won't contain a comma, you can add another optional non-capturing group in your regex like this:

^(?!.*\b(?:https?:\/\/|www\.))\w+(?:\.\w+)*\.\w{2,}(?:\/[^,]*)?(?:,\w+(?:\.\w+)*\.\w{2,}(?:\/[^,]*)?)*$

RegEx Demo

Note addition of an optional non-capturing group in regex:

  • (?:\/[^,]*)?: That matches text starting with / followed by 0 or more of any character except a comma. ? makes this group optional
Sign up to request clarification or add additional context in comments.

1 Comment

but is it possible to make it accpept multiple links not just two? like it should match google.com/home.php?,facebook.com/pages/#ref=?,facebook.com,google.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.