Regular expression for mail address

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
User avatar
^rooker
Site Admin
Posts: 1484
Joined: Fri Aug 29, 2003 8:39 pm

Regular expression for mail address

Post by ^rooker »

Actually, I just wanted KDE's Klipper to be able to compose a new mail when selecting any mail address instead of its default "mailto:" prefix.

So I wrote this regular expression:

Code: Select all

(\w|-|\.)+@(\w|-|\.)+\.\w{2,3}
...and associated it with this command (to open thunderbird):

Code: Select all

mozilla-thunderbird -compose to=%s
The regexp should match most of existing mail addresses. Here's a short explanation of it:
[li](\w|-|\.) = Any word character (a-z, 0-9, _, ...) or "-" or a dot[/li]
[li]+ = at least once[/li]
[li]@ = just the "at" sign[/li]
[li](\w|-|\.)+ = again: some word character(s)[/li]
[li]\.\w{2,3} = ...followed by a dot and then 2 or 3 word characters[/li]

voila.
Now have fun selecting some text like "mymail@yourisp.com" and press "Ctrl+Alt+R" (default shortcut for Klipper's actions!"
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply