• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

Strip first comment

I have this

<!-- Generated by abcdefg --><p>sdsdsd</p>

I need to remove the first comment that is <!-- Generated by abcdefg --> and leave the rest intact.
Hopefully, I need to use regex.
0
ansi_c
Asked:
ansi_c
1 Solution
 
DarkoLordCommented:
if abcdefg is always the same, you can just use:

string removed = data.Replace("<!-- Generated by abcdefg -->", String.Empty);
0
 
DhaestCommented:
Without regex:

        Dim myString As String = "<!-- Generated by abcdefg --><p>sdsdsd</p>"
        myString = myString.Substring(myString.IndexOf("-->") + 3)
0
 
ansi_cAuthor Commented:
No. It's always changing.
And I want a regular expression solution.
0
 
DarkoLordCommented:
Very well.

data = Regex.Replace(data, "^<!-- Generated by .+? -->", String.Empty);
0
 
mrkarrCommented:

you might want to limit that a bit, if you only have "A-Z" in the list with no spaces

data = Regex.Replace(data, @"^<!-- Generated by \w* -->", String.Empty);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now