Chat
Chat

Reputation: 185

Replace string using pattern in XML string in Sql Server

I would like to replace span tags from XML string using regex from multiple records in a column of type string.

Looking for how to remove starting span tags for Ex: "<span class="TAGGED_ITEM " id="c1_ae1">"

Will be able to replace "</span>" with Empty string.

Here is the Input.

    <Item title="1234" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2">
        <ItemBody>
        <div class="item_text">
                        <div>
                            <span class="TAGGED_ITEM " id="c1_ae1">This is a map on a grid.</span>
                            <span class="TAGGED_ITEM " id="c1_ae2"> It shows a car.</span>
                        </div>
                            <span class="TAGGED_ITEM " id="c1_ae3"> It shows a car on Road.</span>
                    </div>
        </ItemBody>
    </Item>

Here is output.

  <Item title="1234" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2">
        <ItemBody>
        <div class="item_text">
                        <div>
                            This is a map on a grid.
                             It shows a car.
                        </div>
                           It shows a car on Road.
                    </div>
        </ItemBody>
    </Item>

Upvotes: 0

Views: 573

Answers (2)

Leptonator
Leptonator

Reputation: 3499

If you really want to replace your span tags, this should do it for you.

<span class[^>]*>|<\/span>

have a look here: DEMO

Upvotes: 1

Ashraful Islam
Ashraful Islam

Reputation: 12830

Use this regex to replace span tag with empty string

<span.+?>|<\/span>

For your Input the above regex select span tag : enter image description here

Upvotes: 1

Related Questions