Here's my problem. I want to replace all the "document 1", "document 12" strings in a text by an hypertext link :
<a onclick="gotodocument(document7);">document 7</a>
I tried this code :
var reg=new RegExp("((document )[a-zA-Z0-9/.]+)+\s(\w+)","gi");
var chaine= *thetext*;
var socle_contenu = chaine.replace(reg, "<a onclick=\"alleraudocument('$1');\"'>" + '$1' + "</a>");
The result is :
<a onclick="gotodocument(document 7);">document 7</a>
As you can see, the problem is the space in the onclick function.
I tried to delete this space but I want to keep this space for the human reader. I couldn't make it.
I then tried to get "document " and the number in $1 and $2, in order to contacatenate the two variables as I need. I tried this :
var reg=new RegExp("((document )\s(\w+))+", "gi");
But it doesn't work ! Can anyone tell me how to setup the regular expression ?
Thanks !