4

How can I define a command to retain only the domain name of a link e.g. http://www.google.com/search?=bang will give only google.com and display it as organisation field for a url reference?

Many Thanks

2

This is really a non-trivial request, and I strongly advise to fill out the organization field manually (your least problem is capitalisation of the organization's name: you would not want url = {http://nssdc.gsfc.nasa.gov/planetary/factsheet/moonfact.html} to come out as organization = {nasa}, but organization = {NASA}).

Some more or less useful solution as a proof of concept with biblatex and biber.

This sourcemap goes into the preamble.

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite=false]{
      \step[fieldsource=url, match=\regexp{^((?:f|ht)tps?://)?(?:www\.)?([^/]+)}, final]
      \step[fieldset=organization, fieldvalue={$2}]
    }
  }
}

It tries to extract the domain part of a URL from the url field and maps it to the organization field. Since getting rid of sub-domains is not a trivial task especially if you take into account that there are TLDs like .co.uk, .info, .de, .com etc., these are still included.

\documentclass{article}

\usepackage[style=authoryear, backend=biber]{biblatex}

\usepackage{hyperref}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@ELECTRONIC{MEMSnet,
  title = {What is {MEMS}?},
  url = {http://www.memsnet.org/mems/what_is.html},
  urldate = {2013-12-01},
}
\end{filecontents}

\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite=false]{
      \step[fieldsource=url, match=\regexp{^((?:f|ht)tps?://)?(?:www\.)?([^/]+)}, final]
      \step[fieldset=organization, fieldvalue={$2}]
    }
  }
}

\begin{document}
  \nocite{MEMSnet,wilde,markey}
  \printbibliography
\end{document}

gives

enter image description here

Both issues mentioned above can be observed here: One would probably want to see MEMSnet instead of memsnet.org, and CTAN instead of tug.ctan.org.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.