Looking for a regex to match a gmail plus address
Im using this currently :
/^(.*)\+(.*)@gmail.com/
(I'm capturing the text before and after the plus sign in a group)
and it works in most cases s开发者_如何学Cuch as
test+test@gmail.com
but falls down if I try to match say
test+++test@gmail.com
The repeated + signs seem to screw it up.
Any help would be much appreciated.
Thanks
(.*?)\++(.*?)@gmail.com
should work.
you need to escape the + sign : /^(.+?)\++(.+?)@gmail.com/
EDIT : your post was misformatted : your + is already escaped
You are not properly detecting the +. Use something like this: ^([^+]+)[+]+([^+]+)@gmail.com
[a-zA-Z0-9]{1,}[\+]{0,}[a-zA-Z0-9]{0,}@gmail.com
You can use [] with ^ (all the chars but...) e.g.
echo 'aaa++++bbb@gmail.com' | perl -p -e 's/^([^\+]*)\+(.*)@gmail.com/$1/'
If you don't care about validating the first portion of the address (prior to any '+') you could go with /^([^+]+)(:?+[^+]*)*@gmail.com/
to just the first part.
You may want to do better validation on that to ensure that it is a "valid" account format, according to whatever rules are set forth by RFC.
edit -- asterisks were making a bold statement.
I think this can be simplified a touch:
IF you know the address you're looking for and want to match your address regardless of whether it has a 'plus' tag on it:
bignev(\+.*)*@gmail.com
If you only want the ones with the 'plus' tag:
bignev(\+.*)@gmail.com
If you have your own domain:
bignev(\+.*)*@everton.com
Or to answer the original post specifically:
.*(\+.*)@gmail.com
精彩评论