Home > Net >  Visual studio code find replace another part of the string used in the find
Visual studio code find replace another part of the string used in the find

Time:03-31

I am using visual studio code to find and replace another part of the string. The string will always contain the string "sitemap" without the quotes but i want to remove index.html

Some examples of what i need replaced: front/index.htmltemplate.xsl to front/template.xsl

com/index.htmlwp-sitemap to com/wp-sitemap

Some my attempts on the vs studio code regex search box incude sitemap[^"']*index.html and sitemap.*?(?=index.html)

but neither is identifying all of the strings that need replacing

CodePudding user response:

This might do the trick for you: (index\.html)(?=. (sitemap))

Explanation:

  • () = Group multiple tokens together to create a capture group
  • (index.html) = Create a capture group around your target string to replace
  • (?=. (sitemap)) = Create a capture group for sitemap and allow for any type and number characters between sitemap and index.html until reaching "sitemap".
  • ?= means this is a "positive lookahead" meaning it will match a group after the main expression without including it in the result. In this case it means it will match sitemap and any chars before it without including it in your result -- so you just get index.html.

https://regexr.com/6iipm

  • Related