Question: I am using the following Regular Expresion to remove html tags from a string. It works except I leave the closing tag. If I attempt to remove: `<a href="blah">blah</a>` it leaves the `<a/>`.

I do not know Regular Expression syntax at all and fumbled through this. Can someone with RegEx knowledge please provide me with a pattern that will work.

Here is my code:

```
  string sPattern = @"<\/?!?(img|a)[^>]*>";
  Regex rgx = new Regex(sPattern);
  Match m = rgx.Match(sSummary);
  string sResult = "";
  if (m.Success)
   sResult = rgx.Replace(sSummary, "", 1);

```

I am looking to remove the first occurence of the `<a>` and `<img>` tags.

Answer: 
To turn this:

```
'<td>mamma</td><td><strong>papa</strong></td>'

```

into this:

```
'mamma papa'

```

You need to replace the tags with spaces:

```
.replace(/<[^>]*>/g, ' ')

```

and reduce any duplicate spaces into single spaces:

```
.replace(/\s{2,}/g, ' ')

```

then trim away leading and trailing spaces with:

```
.trim();

```

Meaning that your remove tag function look like this:

```
function removeTags(string){
  return string.replace(/<[^>]*>/g, ' ')
               .replace(/\s{2,}/g, ' ')
               .trim();
}

```
Simple way,

```
String html = "<a>Rakes</a> <p>paroladasdsadsa</p> My Name Rakes";

html = html.replaceAll("(<[\\w]+>)(.+?)(</[\\w]+>)", "$2");

System.out.println(html);

```