0

I do not know how to better track down the question. What I want to do is to look for every e-mail-address matching my regEx in different div.test, to create <a href="mailto:"> links.

This does work, but if there are multiple mail addresses inside one div, only the first one gets highlighted. Whats the problem?

var regEx = /(\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)/;

$(".test").filter(function() {
    return $(this).html().match(regEx);
}).each(function() {
    $(this).html($(this).html().replace(regEx, "<a href=\"mailto:$1\">$1</a>"));
});

JSBIN

2

1 Answer 1

2

You must add the global (g) flag to you regexp:

var regEx = /(\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)/g

Otherwise your regex will halt after the first match.

Sign up to request clarification or add additional context in comments.

Comments

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.