Replace with regex keeping part of the pattern

前端 未结 1 1744
轻奢々
轻奢々 2021-01-14 13:52

In the example below, how to preserve part of a pattern? The pattern search must include closing tag as spans elsewhere must not be targeted.

<
相关标签:
1条回答
  • 2021-01-14 14:32

    You need to set a capturing group and use a back reference in the replacement pattern.

    regEx.Pattern = "</span>([^>]*)</h3>"
    hr2 = regEx.Replace(hr2,"$1</h3>")
    

    Or

    regEx.Pattern = "</span>([^>]*</h3>)"
    hr2 = regEx.Replace(hr2,"$1")
    
    0 讨论(0)
提交回复
热议问题