This will work well on names separated by '-' and the either any amount of numbers and letters separated by '-', inducing none. It will give you back the letter and numberParts parts with ?pdf= appended to the end of the URL.
var value = "http://mysite/strategy/annual-plan-16-17.pdf";
var matches = value.replace(/([^\/\s]+)(.pdf)/g, "$1$2?pdf=$1");
console.log(matches)
This is done by splitting the matching into 2 groups with (), these are:
the first one takes the names separated by dashes using [^/\s.]+ to get any number of any character not a '\', '.',or a white-space, this basically gets all the characters from the '.pdf' to the / before it.
This next group matches .pdf using .pdf (obviously)
It then replaces this match with the whole match plus + ?pdf= + the first group.
If you wish jsut the letter part so xxxxx-xxxxx-1111.pdf gose to .pdf?pdf=xxxxx-xxxxx, then you can use this.
var value = "http://mysite/strategy/annual-plan-16-17.pdf";
var matches = value.replace(/([^\/0-9]*[^-\/0-9])(-??[^/.]*)(.pdf)/g, "$1$2$3?pdf=$1");
console.log(matches)
This is done by splitting the matching into 3 groups with (), these are:
the first one takes the names separated by dashes using [^./0-9]* to get any number of any character not a '.', '/' or a digit, it then uses [^-./0-9] to make sure the match doesn't end with a '-'. This effectively matches words separated by - that don't contain numbers.
This group uses -?? to match as few - as possible (including none), it then follows with [^/]* which matches anything that doesn't have a '^' or a '/'. This effectively matches words separated by - that contain numbers.
uses .pdf to match .pdf. If you wanted to ensure it was at the end of a string you could use .pdf$
This match is then replaced with itself + ?pdf= + the first matching group.