Find your content:

Search form

You are here

REGEX for stripping http://, https:// and www from website

 
Share

For a custom field "Domain," I want to strip extraneous elements like those in the subject line, which often end up in the field through web-to-lead. Can anyone suggest a REGEX formula for stripping those elements?


Attribution to: Scott_in_London

Possible Suggestion/Solution #1

Update: I think I've misinterpreted your requirements for scrubbing fields that shouldn't contain URLs. Still, I'll leave this here as my preferred method for parsing the elements of a URL.


Personally, I'd skip the Regex and utilise the built in System.URL class.

string urlAsString = 'http://salesforce.stackexchange.com/questions/30408/regex-for-stripping-http-https-and-www-from-website';
System.Url parsedUrl = new System.Url(urlAsString);
System.debug(parsedUrl.getHost());
System.debug(parsedUrl.getPath());

Outputs:

salesforce.stackexchange.com
/questions/30408/regex-for-stripping-http-https-and-www-from-website

You may also need the Port and Query depending on your requirements.


Attribution to: Daniel Ballinger
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/30408

My Block Status

My Block Content