2

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 :(

2
  • Literally, "JJDnnnnnnnnnnnnnnnn", or do the n's represent numbers? Commented Feb 23, 2009 at 19:56
  • sorry yes, i should be more specific the n's represent 0-9 Commented Feb 23, 2009 at 20:00

1 Answer 1

3

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>");
Sign up to request clarification or add additional context in comments.

1 Comment

I feel such a fool. Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.