改进此正则表达式以包括它匹配的内容,直到它匹配某个字符

Can someone please help me improve this regex so that it captures everything that starts with http://, https://, or www and then continues until it reaches a ' or ". It includes punctuation and is case-insensitive.

Here is the regular expression right now:

(wwww|https?://)
/(?:https?:\/\/|www)[^'"]*/i

I escaped the slashes since they could conflict if you use /.../ notation. [^'"] is an inverted character class that allows everything but quotes.

Edit: I removed the caret to match any occurrence of the pattern, :? to make the group non-capturing.

@(www|https?://).*?(?=['"])@i

The .*? makes the quantifier reluctant so it will stop at the first quote rather than the last.

The following regex will work:

(?:https?:\/\/|www)[^'"]*

You can walk through the details of the match at www.debuggex.com.