jthompson
jthompson

Reputation: 921

JavaScript Regexp Replace?

I'm trying to come up with a regular expression which will wrap all occurences of JJDnnnnnnnnnnnnnnnn within a string with an anchor pointing to an url which contains the matched string in the query string.

I suck at regexps :(

Upvotes: 2

Views: 642

Answers (1)

Daniel LeCheminant
Daniel LeCheminant

Reputation: 51071

To replace JJD with exactly 16 digits after it, you could say

str.replace(/(JJD[0-9]{16})/gi,"<a href='somepage.html/foo?value=$1'>$1</a>");

if you don't need exactly 16 digits, but need something like 10-20 digits, you could say

str.replace(/(JJD[0-9]{10,20})/gi,"<a href='somepage.html/foo?value=$1'>$1</a>");

Upvotes: 3

Related Questions