Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove all label tags inside a string

I want to remove all label tags from a string.

This is the input string.

<p>
<title>Contact Us</title>
</p>
<table dropzone="copy">
    <tbody>
        <tr>
            <td class="label" style="cursor: default;">Full Name</td>
            <td style=
"cursor: default;">[<label id="{0a4a7240-9606-416a-bf7b-ef11a47cca8e}">First name</label>] [<label id="{94263497-683b-46f9-ba0f-69f4c2736598}">Last name</label>]</td>
        </tr>
        <tr>
            <td class="label" style="cursor: d
efault;">Telephone</td>
            <td style="cursor: default;">[<label id="{ce68e02e-e9fd-40ee-9375-ee1b05972e9b}">Phone</label>]</td>
        </tr>
        <tr>
            <td class="label" style="cursor: default;">Email</td>
  <td style="cursor: default;">[<label id="{411b580e-f7e9-4dd2-a70d-947385360cd0}">Email</label>]</td>
        </tr>
        <tr>
            <td class="label" style="cursor: default;">Message</td>
            <td style="cursor: default;">[
<label id="{13e2ff23-135c-4c6d-beb4-2960a533cb98}">Your Message</label>]</td>
        </tr>
        <tr>
            <td class="label" style="cursor: default;">Company</td>
            <td style="cursor: default;">[<label id="{c3f22c3a-8fc1
-48a4-8d6a-fe346024ca2b}">Company</label>]</td>
        </tr>
    </tbody>
</table>
<p> </p>
<p> </p>

The label tag needs to be removed but value inside the string should not be removed

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<label id="{0a4a7240-9606-416a-bf7b-ef11a47cca8e}">First name</label> will become First name

<label id="{ce68e02e-e9fd-40ee-9375-ee1b05972e9b}">Phone</label> will become Phone

<label id="{411b580e-f7e9-4dd2-a70d-947385360cd0}">Email</label> will become Email

<label id="{13e2ff23-135c-4c6d-beb4-2960a533cb98}">Your Message</label> will become Your Message

<label id="{c3f22c3a-8fc1-48a4-8d6a-fe346024ca2b}">Company</label> will become Company

I tried the following regex [Regex]::Match( $text, ‘(?s)<label(.*)">’ ).Groups.Value but its not working.

Any suggestions would be appreciated

Thanks in advance

>Solution :

This regex could work, you can use the -replace operator instead of the call to Regex.Replace:

(Get-Content path\to\file -Raw) -replace '<label id="\{[\d\w-]+}">([a-z ]+)<\/label>', '$1'

See https://regex101.com/r/3gbJEp/1 for details.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading