The extractRepoName function takes a string representing a GitHub URL, e.g. https://github.com/northcoders/intro-week. In this example, northcoders is the name of the account and intro-week is the name of the repo.
The function should return a string of just the repo name.
Although there are multiple ways of achieving this, make sure to use a regular expression.
Example
extractRepoName(“https://github.com/northcoders/intro-week”) // returns “intro-week”
extractRepoName(“https://github.com/northcoders/remote-git-workshop”) // returns “remote-git-workshop”
extractRepoName(“https://github.com/myAccount/notes”) // returns “notes”
extractRepoName(“https://github.com/myAccount/notes/settings”) // returns “notes”
function extractRepoName(str) {
const regex = //([^/]+)/?$/;
const match = str.match(regex);
return match ? match[1] : null;
}
i still have this error below :
*** ”should return the repo name from a URL with extra information”
✕ AssertionError: expected ‘settings’ to equal ‘fe-katas’***
i think i didnt know how match every instance after a slash, and then returning the 2 index position.
Mohamed Belhadj Mohamed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.