How to Extract Authors and Title from a Reference List using JS
The provided function extracts authors and titles from all reference list formats
How to Extract Authors and Title from a Reference List using JS
The provided function extracts authors and titles from all reference list formats

TLDR:
JavaScript function to extract authors and title from reference
Background
The blog site I’m building (Sapien Think) includes Amazon Affiliate links to works referenced in articles. At first, I tried to link to the entire reference text, but this yielded very poor search results within Amazon.
ex:
Kant, I. (2012). Groundwork of the Metaphysics of Morals. Cambridge University Press.doesn’t search nearly as well asKant, I, Groundwork of the Metaphysics of Morals.
To solve this, I needed to extract important information like author(s) and title from references. This would be easy if a single format was used for reference lists in my site, but that’s not the case. For example, here are some varying references:
- Kant, I. (2012). Groundwork of the Metaphysics of Morals. Cambridge University Press.
- Descartes, R. Meditations on First Philosophy.
- Russell, Bertrand. “The History of Western Philosophy.” Routledge, 2004.
- Russo, N. F., & Epistemology, F. in. (1989). Developing Philosophical Thinking Skills in Learning Experiences. Theory Into Practice, 28(2), 102–105. doi:10.1080/00405848909543340
How can we efficiently deal with all those varying reference types?!
1. Separate into Sections
First, notice the nice fact that the various parts of all the references are separated by . (a period followed by a space).
So the first thing we can do is separate the original string on this pattern:
const extractAuthorsAndTitle = (reference) => {
reference = reference.split('. ');
};
Now, we’ve converted our reference into an array of strings, each being an important section (author, title, date, publisher, …).
2. Handle Bad Author Sections
The above trick works nicely if author initials aren’t listed. However, once we encounter something like: Russo, N. F. we have issues. Our split operation will split on the initials, so the first part of our array will look like: ['Russo, N', 'F', ...] — not desireable.
To prevent this, we can use regex to collapse a sequence of initials:
A. B. C. collapses to become A. .
Here’s the code that can do that:
const regex = /([A-Z])\.(\s[A-Z]\.)+/g;
reference = reference.replace(regex, '$1.');
After applying this code, an author like Russo, N. F. becomes Russo, N. .
3. Remove Quotation Characters
Before we split on . , we also want to remove any " characters. There are two reasons for this:
- Quotation marks are irrelevant to article titles
- They can mess up our string splitting:
hello."won’t split buthello.will.
This one is pretty simple:
reference = reference.replace(/"/g, '');
4. Remove Irrelevant Reference Data
After all the above steps, after we’ve split the reference on . , we’re almost done. Now we just need to remove unnecessary data. This includes stuff like the following:
(2006)inPaul, R., & Elder, L. (2006). *Critical Thinking: The Nature of Critical and Creative Thought*. Journal of Developmental Education, 30(2), 34–35.(Eds.)inFieser, J., & Dowden, B. (Eds.). (2020). *The Internet Encyclopedia of Philosophy*.in.inRusso, N. F., & Epistemology, F. in. (1989). *Developing Philosophical Thinking Skills in Learning Experiences*. Theory Into Practice, 28(2), 102–105.
We can do this with some filtering steps after the split, like this:
const sections = reference.split('. ');
const filteredSections = sections
.filter(str => str[0] !== '(')
.filter(str => str !== 'in');
5. Putting it All Together
Finally, once we have our filtered sections, it turns out that (at least for most reference formats), the author(s) will be contained in the first array element, and the title of the work will be in the second.
Our final function looks like this:
const extractAuthorsAndTitle = (reference) => {
// process author lists with middle name initials
// collapses patterns like 'G. W. F.' to 'G.'
const regex = /([A-Z])\.(\s[A-Z]\.)+/g;
reference = reference.replace(regex, '$1.');
// remove all " characters
reference = reference.replace(/"/g, '');
// split and filter
const sections = reference.split('. ');
const filteredSections = sections
.filter(str => str[0] !== '(')
.filter(str => str !== 'in');
return [filteredSections[0], filteredSections[1]];
};
That should be able to handle most reference list formats, and it can easily be modified to handle even more edge cases.
메타데이터
- post_id
- 5df291da1f2c
- slug
- how-to-extract-authors-and-title-from-a-reference-list-using-js-5df291da1f2c
- url
- https://medium.com/@lkuppers11/how-to-extract-authors-and-title-from-a-reference-list-using-js-5df291da1f2c
- canonical_url
- https://medium.com/@lkuppers11/how-to-extract-authors-and-title-from-a-reference-list-using-js-5df291da1f2c
- author_url
- https://medium.com/@lkuppers11
- status
- ok
- fetched_at
- 2026-06-26 03:39:16