Q:

Java Regex xml parsing

I'm trying to find a tag from begin to end in xml and replace it with a blank. A sample xml is like this
<lins>
  <lin index="1"> ...<feature>Something</feature>... </lin>
  <lin index="2">...<feature>Something</feature>... </lin>
  <lin index="3">...<feature>Something</feature>....</lin>

  <lin index="1">...<feature>Icom</feature>... </lin>
  <lin index="2">...<feature>Icom</feature>... </lin>
<lins>

I need to remove <lin> to </lin> when ever I see  Icom in between
<lin\s(.+?Icom.+?)+</lin> is removing all lin items since it matches the first begin <lin> tag and the last lin end tag. Greatly appreciated if you can suggest a way to do this. Also I can not use xml parsers in my situation.

A:

String result = subject.replaceAll("(?s)<lin\\b(?:(?!</lin).)*Icom(?:(?!</lin).)*</lin>", "");

should do this, unless you have <lin> tags nested into each other (or inside comments/strings). 
Explanation:
<lin\b              # Match <lin (but not link or linen)
(?:                 # Match...
 (?!</lin)          # as long as we're not at a closing tag
 .                  # any character
)*                  # any number of times.
Icom                # Match Icom
(?:(?!</lin).)*     # (as above:) Match any character except closing tag
</lin>              # Match closing tag

