Using search and replace on URL query string

Bruce Johnson

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.

aaron_world_traveler

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Replace portions of a url path and query string using .htaccess and Regex?

From Dev

How to replace query string value in the url using Jquery

From Dev

Replace URL query string with slash for a friendly URL

From Dev

Replace URL query string with slash for a friendly URL

From Dev

search and replace string using batch or perl script

From Dev

How to replace query parameter in URL using Regex?

From Dev

How to replace query parameter in URL using Regex?

From Dev

Search AngularJS resource using query string

From Dev

Search AngularJS resource using query string

From Dev

search the inbetween string using sql query

From Dev

Elasticsearch query_string search using wildcard

From Dev

Mysql Search and Replace query

From Dev

Search and Replace in string in D

From Dev

Search and replace the string

From Dev

Search and replace in string

From Dev

Python search and replace in a string

From Dev

Search and Replace in string in D

From Dev

Search and replace the string

From Dev

search and replace string with patterns

From Dev

search and replace a string in cell

From Dev

Search string and replace value

From Dev

Retrofit error URL query string must not have replace block

From Dev

Search and replace a string using Windows shell or Perl script

From Dev

Using Java Pattern and Matcher to search and replace string before the XML declaration

From Dev

Search Multiple string using Visual Studio IDE Find and Replace

From Dev

Replace string in every line with a search result using Vi/Vim

From Dev

Search and replace a string pattern in python using regular expressions

From Dev

Using a url query string to jump to page sections

From Dev

Rewrite URL using .htaccess with a static query string

Related Related

  1. 1

    Replace portions of a url path and query string using .htaccess and Regex?

  2. 2

    How to replace query string value in the url using Jquery

  3. 3

    Replace URL query string with slash for a friendly URL

  4. 4

    Replace URL query string with slash for a friendly URL

  5. 5

    search and replace string using batch or perl script

  6. 6

    How to replace query parameter in URL using Regex?

  7. 7

    How to replace query parameter in URL using Regex?

  8. 8

    Search AngularJS resource using query string

  9. 9

    Search AngularJS resource using query string

  10. 10

    search the inbetween string using sql query

  11. 11

    Elasticsearch query_string search using wildcard

  12. 12

    Mysql Search and Replace query

  13. 13

    Search and Replace in string in D

  14. 14

    Search and replace the string

  15. 15

    Search and replace in string

  16. 16

    Python search and replace in a string

  17. 17

    Search and Replace in string in D

  18. 18

    Search and replace the string

  19. 19

    search and replace string with patterns

  20. 20

    search and replace a string in cell

  21. 21

    Search string and replace value

  22. 22

    Retrofit error URL query string must not have replace block

  23. 23

    Search and replace a string using Windows shell or Perl script

  24. 24

    Using Java Pattern and Matcher to search and replace string before the XML declaration

  25. 25

    Search Multiple string using Visual Studio IDE Find and Replace

  26. 26

    Replace string in every line with a search result using Vi/Vim

  27. 27

    Search and replace a string pattern in python using regular expressions

  28. 28

    Using a url query string to jump to page sections

  29. 29

    Rewrite URL using .htaccess with a static query string

HotTag

Archive