Skip to content
Advertisement

JavaScript, regex: How to fetch mail address in mailto: links

Is there a jquery plugin or may be a regex which can be used to all the fields in query string of a mailto: link. It should support the mailto syntax.

Say if I have a link like …

<a href="mailto:astark1@unl.edu,id@internet.node">Some msg</a>

The regex should give me the mail addresses in mailto: link – astark1@unl.edu, id@internet.node. It should also support links like

<a href="mailto:astark1@unl.edu?subject=Comments from MailTo Syntax Page">
<a href="mailto:astark1@unl.edu?body=I am having trouble finding information on">
<a href="mailto:astark1@unl.edu?subject=MailTo Comments&cc=ASTARK1@UNL.EDU&bcc=id@internet.node">

For a link like

<a href="mailto:value">tell a friend</a>

I would pass value and the function and get an associative array of email addresses and other fields passed in query string.

Advertisement

Answer

Parsing URLs, and especially their query strings, is not a job for regexes. You could use a proper URL-parsing library or perhaps just a query string parsing one.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement