But I need to write a function that takes in a string, looks for a URL in a hyperlink and then swaps the url around so that the page name is now used as an anchor so for example
<a href="mysection/mysector/apage.aspx">
would become
<a href="mysection/mysector.aspx#apage">
but this would only happen for links in the mysector folder.
I am a bit stumped at the moment and any help would be great.
This will eat all sequences of “folder/” and catch the last of them. This gets appended an “.aspx” and “#” and the filename without extension. Character classes may need further adjustments if your folder and file names can contain not only alphanumeric characters.
then replace with
Also try “mysection/anothersection/yetanotherone/mysector/apage.aspx” to understand how it works.