To only match any string of characters, which do not contain a space and end in ".com", ".net" or ".org":
/[^\s]+\.(?:com|net|org)\b/i
Explanation:
/
= Start of a Regular Expression
[^\s]
= Not (^
) a whitespace (\s
) character
+
= One or more of the preceding set (non-whitespace characters)
\.
= A dot. Dots in RegExps are special characters otherwise
(?: ... )
= A group, but not one to be stored
com|net|org
= com
OR net
OR org
(You can add more here, separated by "|")
\b
= A word boundary - the end of a word
/
= End of the Regular Expression (apart from optional flags)
i
= Insensitive to case
Extension of Answer
At the request of the OP, the below is a (rough) RegExp which should match a URL for a domain ending in the specified strings, and with one or more key=value pairs in the query string.
/[^\s]+\.(?:com|net|org)[^\s]+\?[^\s]+=[^\s]+(?:\&?[^\s]+=[^\s]+)*\b/i
/
= Start of a Regular Expression
[^\s]+\.(?:com|net|org)
= As before
[^\?]+
= One or more non-questionmark characters (this would be any folder or filenames). Again, the Questionmark has a \
before it to have it treated as a normal character, as, otherwise, it has a special meaning here
\?
= A Questionmark
[^\s]+\=[^\s]+
= One or more non-whitespaces, then an equals sign, then one or more non-whitespaces
(?:\&?[^\s]+=[^\s]+)*
= None or more sets of an ampersand &
, then another one or more non-whitespaces, an equal sign, and one or more non-whitespaces
\b
= End of the string
/
= End of the Regular Expression
i
= Insensitive to case
NOTE: This does not look for completely valid URLs, nor does it allow for the multitude of Country Codes (like '.com.au' for Australia), or other Top Level Domains (like '.edu', etc.) But, it will match the example string provided, of twitter.com/example?var=true