Question: the following takes contents of an HTML file (input)

```
input = input.replaceAll(".*?<span class=\"xgui.*?\">(.*?)</span>.*?", "<cite>$1</cite>");

```

The idea is to remove the span element and leave the contents. Note that the class of the span can be xgui *anything*. However, the code is not working.

It spits out this:

```
 <h4><span class="xguiitem">Primary</span> field </h4>

```

Which is identical to input; ie, it is not doing anything at all.

Any ideas?

Thanks :)

Answer: 
As a starting note (as also mentioned in the comments): please do not parse arbitrary HTML using regular expressions.

Nevertheless if you know the html structure beforehand and if you have a very specific task you might do it with a regex replacement.

In your case the expression works almost fine. Just a remark about the `.*?` at the beginning and the end of your expression:

* `.*?` at the end will not match anything at any time, because it can not get ungreedier than matching nothing.
* `.*?` at the beginning will match anything from start to the actual `<span...` because a match starting early will always count higher than any non-greediness.

Thus, you can get rid of them and use the following

```
input = input.replaceAll("<span class=\"xgui.*?\">(.*?)</span>", "<cite>$1</cite>");

```
I don't understand why you have those "?" all over, can you try:

```
input = input.replaceAll(".*<span class=\"xgui.*\">(.*)</span>.*", "<cite>$1</cite>");

```