I'm using javascript to determine which directory an article is in, and self-generate all the file paths in the page. I've got it working, except that I still need to manually input the year the page was created as a variable when the article is moved from a 'recent' directory into the archive. I'm hoping to fully automate the process by using javascript to return the value of a specific directory in the file path.
For example, if the file path is: news/foo/2015/bar/article.html I need to extract the text '2015' and place it in a variable named 'year'.
Note the directory names won't be consistent, so I don't think searching the string for 'foo' or 'bar' is an option, rather the script needs to return the text between the second-last and third-last forward slash, or just the last 4 characters before the second-last forward slash. Thanks.