I need to remove the tag “image” with regex.
I’m working with C# .Net
example <rrr><image from="91524" to="92505" /></rrr> should become:
<rrr></rrr>
Anyone???
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You shouldn’t really be using regex for this task, especially when .NET provides such powerful tools to handle XML:
However if you insist on doing this with regex, let’s see what happens:
This method has some problems though that the first method solves for you. Example problems:
>characters in attributes can confuse the regex.<image2 />.<image />and<image></image>.Some of these are easy to fix, some are more tricky. But in the end it’s not worth spending time improving the regular expression solution to handle all the special cases when the LINQ to XML solution is so simple and does all this for you.