I have the following HTML:

```
<div class="subjectList">
    <p>PHM315 Pharmacy Practice 2
        <br/>PHM101 Introduction to Pharmacy
        <br/>PHM215 Pharmacy Practice 1
        <br/>PHM490 Rural Pharmacy Practice</p>
</div>

```

I'd like to search for any string which matches the following pattern:

```
/([A-Z][A-Z][A-Z][0-9][0-9][0-9])/g

```

And wrap that matched text with a url.

Essentially,

```
<p>PHM315 Pharmacy Practice 2

```

becomes:

```
<p><a href="/PHM315">PHM315</a> Pharmacy Practice 2

```

I almost have this working, using this jQuery

```
var replaceSubjectCode = "<a href=\"/subjects/$1.html\">$1</a>";
var str = $('.subjectList p').html();
str = str.replace(/([A-Z][A-Z][A-Z][0-9][0-9][0-9])/g, new RegExp(replaceSubjectCode));
$('.subjectList p').html(str);

```

However it outputs the following:

```
<div class="subjectList">
 <p>/<a href="/subjects/PMH315">PHM315</a>/ Pharmacy Practice 2<br/>

```

Note the additional "/" outside the < a > tags.

Any assistance in removing these forward slashes would be greatly appreciated. I have tried running a RegExp replace using ///g - but I cannot seem to get it to ignore the hyperlink.

See fiddle: [<http://jsfiddle.net/qWP43/1/>](http://jsfiddle.net/qWP43/1/)