So my company rebuilt their entire intranet, and since they're not implementing 301 redirects, there are now loads of invalid links in company Word documents.
I have created a macro but need help with the regex so that I can find links of the format:
http://foo/bar/baz.php?id=string1:string2:string3:string4
and replace them with:
https://abc/def/ghi/string1/string2/string3/string4.aspx
Note that string2, string3 and string4 are not always present.
My attempt
search: http://foo/bar/baz.php\?id=([\w]*):?([\w]*):?([\w]*):?([\w]*)
replace: https://abc/def/ghi/$1/$2/$3/$4.aspx
The issue with this is that if string2, string3 or string4 aren't present, I end up with something like http://abc/def/ghi/string1///.aspx
I'd really appreciate any help you can give me. You don't have to use VBA regex in your answer.
I'd simply grab the whole string1:string2:...
section, and replace the colons with slashes, put it in the url format you want, and append .aspx
. So, your main regex would then just grab the query string after ?id=
:
http://foo/bar/baz.php\?id=(.*)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments