Extract domain from text: Difference between revisions

Tag: wikieditor
 
Line 20: Line 20:


Explanation:
Explanation:
* Domain refers to text that starts with <nowiki>http://</nowiki> or <nowiki>https://</nowiki>, followed by multiple characters that are not the symbol {{kbd | key = <nowiki>/</nowiki>}}: {{kbd | key = <nowiki>[^/]+</nowiki>}}. =
* Domain refers to text that starts with <nowiki>http://</nowiki> or <nowiki>https://</nowiki>, followed by multiple characters that are not the symbol {{kbd | key = <nowiki>/</nowiki>}}: {{kbd | key = <nowiki>[^/]+</nowiki>}}.
 
If the preference is to not include the schema (<nowiki>http://</nowiki> or <nowiki>https://</nowiki>) in the output, wrap the domain portion in a capture group instead:
<pre>
=REGEXEXTRACT(A2, "http[s]?\://([^/]+)")
</pre>
 
Input text:
<pre>
Example domain https://www.example.com/
</pre>
 
Output:
<pre>
example.com
</pre>
 
Explanation:
* REGEXEXTRACT returns the first capture group when one is present, rather than the whole match. Here the schema (<nowiki>http[s]?\://</nowiki>) is matched but left outside the parentheses, while only the domain part {{kbd | key = <nowiki>[^/]+</nowiki>}} is enclosed in {{kbd | key = <nowiki>(...)</nowiki>}}, so only the domain is returned.


== Data Validation: Does the article content contain a domain ==
== Data Validation: Does the article content contain a domain ==