I have text fields that contains one or multiple occurrence of some code like "XX00123" or "XX00456", for example,
The XX00123 is a sibling of XX00456 and parent of XX00789
I would like to use regex to replace each occurrence of the code thing with a link to it. The result of above example would be then,
The <A HREF='http://server.com/XX00123'>XX00123</A> is a sibling of <A HREF='http://server.com/XX00456'>XX00456</A> and parent of <A HREF='http://server.com/XX00789'>XX00789</A>
I think I could do it with
- put the search result in an array,
- if the array is not empty, construct the text string of the link for each element in the array,
- do a loop to find each occurrence again and replace it with the link
But is there any way to do this regular expression just in one line with JavaScript and/or JQuery?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…