...

View Full Version : Regular Expression



angiras
02-25-2003, 07:17 AM
sorry I don't know where to post it !

I am looking for a regular expression , I mus tfind in full text

mailto: john@starplus.com "

then

what is between mailto: and "

?

thank you

angiras
02-25-2003, 07:18 AM
whithout any space

kwhubby
02-25-2003, 07:48 AM
/mailto:(\w*)"/
should be good (the match would be [1] of the returned results, not [0])

edit: use arq = the variable of the text being searched.match(/mailto:(\w*)"/)
and then arq[1] is what you want

angiras
02-25-2003, 08:22 AM
at once ! :-))

I try it

thank you

kwhubby
02-25-2003, 09:44 PM
oop just relised. \w is for alphabet chars so a @ or . would not give the result

angiras
02-25-2003, 10:29 PM
yes I get nothing at all

then if you have a release version of the regular expression ?
it's welcome !:-))

beetle
02-25-2003, 11:09 PM
var pattern = /mailto:([^"]+)"/;

or

var pattern = /mailto:(\.+?)"/;

Either should work

angiras
02-26-2003, 07:36 AM
I try at once

thank you

liorean
02-26-2003, 03:45 PM
Originally posted by beetle
var pattern = /mailto:([^"]+)"/;

or

var pattern = /mailto:(\.+?)"/;

Either should work


Hmm, /mailto:([^"]+)"/ should work perfectly, but just to be sure, make it case insensitive.

/mailto:(\.+?)"/ on the other hand shouldn't work - you escape the fullstop from being any character to being just a fullstop. You'll not catch any valid address that way.



// This would be better:
var pattern=/mailto:(.+?)"/i;
// But I really suggest you do it in this way instead:
var pattern=/mailto:([-_a-z~.]+@[-_a-z~.]+)"/i;
/* Why? Because that way, even though you'll not get full email address validation out of it, you'll at least make sure you get a full address. */

beetle
02-26-2003, 04:24 PM
Thx liorean, that 2nd pattern is bogus :p

However, I disagree with your 2nd pattern. Email addresses can have an apostrophe as well, and I'm not sure whatever else.

I think "better" is a decision best left up to angiras and what he/she is using these email addresses for.

angiras
02-26-2003, 04:33 PM
it works I get it with

Dim expr As String = "[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}"
Dim patt As String = "mailto:(" + expr + ")"

it's vb Net but regular expressions are the same

thank you to all for helping



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum