Regular expression for complicated email [duplicate] - regex

This question already has answers here:
How can I validate an email address using a regular expression?
(79 answers)
Closed 8 years ago.
I want an regex for email that starts with numbers and letters.
My regex is
/^[a-zA-Z0-9._-]+#[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/
What is wrong in this? It allows ._- from start and in between. But I don't want this
Valid emails = s#gmail.com, s.p#y.com, s_p123#g.com
Invalid emails = ....s#g.com, s---g#g.com, s...#g.com, 44s..p#g.com, ----s#g.com
Does anyone know how this can be done?

So you dont want to have more than one ._- in your regex? And also it shall not start with ._- Try it this way:
^[a-zA-Z0-9]+[._-]?[a-zA-Z0-9]*#[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}
It works for your examples, although im not really sure what email-syntax you really want to test for.
Perhaps you want to use one of many pre written examples in the web (just google ;) )

Related

Replacing a certain number of characters after a match in regular expression [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
I want to find any instance of
\/Network\/Cambric Corporate Center\/
and replace the next 8 characters with nothing.
So something like this
\/Network\/Cambric Corporate Center\/1164.DEV1164
Turns into this
\/Network\/Cambric Corporate Center\/1164
I'm working with a baked in replace regular expression visual programming piece, and this is my first post to here ever so please ask if more info is needed. I basically just need it to look like this
\/Network\/Cambric Corporate Center\/1164
if there is another solution without having to use replace
It is for a frequently updated mass source of data that I need to edit to make more compatible with arrays
Try (\/Network\/Cambric Corporate Center\/).{8} and replace with $1 to keep the first group but not anything else.
Here's the regex with the replacement: https://regex101.com/r/F4Y4VD/1

Use regular expressions to select valid email address [duplicate]

This question already has answers here:
How can I validate an email address using a regular expression?
(79 answers)
Closed 6 years ago.
I came up with the following
([\w.%+-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4})
I would also like to remove emails that start with a number or -. By remove I mean to select only the address and not to remove the entire match.
Is there a way to do that?
^(?:\d+|-+)?([\w.%+-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4})$
This should do the trick. It'll capture emails but also filter out ones that start with a number or the - character and pulls the email from it.

Regex to extract emails not working [duplicate]

This question already has answers here:
How can I validate an email address using a regular expression?
(79 answers)
Closed 7 years ago.
I am trying to extract all the email addresses from pages like this
http://www.quiltguilds.com/alabama.htm
I am using the following RegEX to extract all the emails.
\w+#\w*\.\w*
While this works at online Regex checkers, this isn't working with the import.io application where I am trying to use this to extract all emails.
Can someone kindly review the Regex and confirm if this one would work for extracting just email addresses from a block of text
Many thanks
You can use the following regex:
\S+\#\S+

REGEX email matching [duplicate]

This question already has answers here:
How can I validate an email address using a regular expression?
(79 answers)
Closed 8 years ago.
I have a JAVA string that is being used to validate proper email addresses.
^[\\w'-]+(\\.[\\w'-]+)*#[A-Za-z0-9]+([.-][A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$
I want to user to be able to leave the address blank and not get an error message. How is this possible?
Since you didn't provide any other code or specify what language you were using, the best I can suggest is:
(?:^[\\w'-]+(\\.[\\w'-]+)*#[A-Za-z0-9]+([.-][A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$)|(?:^$)
Which will match an e-mail or an empty string.
If you have an expression you want to make optional allowing empty string to match you could use any of the following:
^(?:regex)?\z
^\z|^regex\z

Regexp to find hostname and subdomain from email address [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Parse email addresses for “from” and “to” fields in Ruby
Given an email address of the form root#host.sub.domain.com, what is the regular expression to get the hostname and the subdomain as two individual variables? I mean $1='host'and $2='sub'?
You help is greatly appreciated :)
EDIT I should say I'm asking about a regular expression to do this, no Ruby code. This is to be used in a postfix configuration file, so I need a regexp. I mistakenly talked about Ruby earlier. My fault, sorry for the confusion.
Non-greedy groups are your friend. They match just what you need:
^(?:.*?)#(.*?)\.(.*?)\.(?:.*?)\.(?:.*?)$