How to use Resharper Structured Search to add a new div that has 3 depth levels?

For example, in the bottom html, find tags divwith classequal bar, as well as parent divequal foo.

// leave this code alone
<div class="bar">
  Hello World!
</div>

// Do a structured find and replace on this code only
<div class="foo">
  <div class="bar">
    Hello World Again!
  </div>
</div>

Here is the resharper search pattern I am using and it does not give any results:

<div class="foo"><div class="bar">$content$</div></div>

The replacement sample should add an additional nested div with the baz class:

<div class="foo"><div class="bar"><div class="baz">$content$</div></div></div>
+6
source share
2 answers

Your approach seems right. This worked for me, for example, define a template like this

Before

Use replace and we get

After

+3
source

There is no reason for your search template to not work.

This is your code.

// leave this code alone
<div class="bar">
  Hello World!
</div>

// Do a structured find and replace on this code only
<div class="foo">
  <div class="bar">
    Hello World Again!
  </div>
</div>

and you tried using

<div class="foo"><div class="bar">$content$</div></div>

If you still cannot search

, HTML

enter image description here

, ( , )

<div class="foo">
  <div class="bar">
    $content$
  </div>
</div>

<$tag$ class="foo">
  <$tag$ class="bar">
    $content$
  </$tag$>
</$tag$>
+2

All Articles