Why is “$1” ending up in my Regex.Replace() result?

后端 未结 4 711
北恋
北恋 2021-01-17 22:10

I am trying to write a regular expression to rewrite URLs to point to a proxy server.

bodystring = Regex.Replace(bodystring, \"(src=\'/+)\", \"$1\" + proxySt         


        
4条回答
  •  北荒
    北荒 (楼主)
    2021-01-17 22:45

    Based on dasblinkenlights answer (already +1) the solution is this:

    bodystring = Regex.Replace(bodystring, "(src='/+)", "${1}" + proxyStr);
    

    This ensures that the group 1 is used and not a new group number is build.

提交回复
热议问题