Regular expression that does not contain 'auto#' - regex

I'm working with a system that processes email addresses and need to tell it to not process email addresses that contain 'auto#' using a regular expression.
Example email addresses:
us.group-email-name.auto#somedomain.com
us.group-email-name#somedomain.com
The regex should only match the second and not the first.
Is this possible?
Thanks in advance for your time!

If you don't have to validate the email addresses and there is no way to do it with a quick built-in substring finder, you can use this regex:
((?!auto#).)*
A far better option would be a simple substring finder method/function, like Java's
emailAddress.indexOf("auto#")
which returns -1 if it doesn't find a match.

Related

Extract domain from email address with Regex

I'm learning regular expressions and I'm having trouble extracting the domain from the email address. I have an email address: example#gmail.com. I need to use a regular expression to extract #gmail (along with the # symbol). I should end up only getting example. I've already tried this:
your text#(\w+)
and this
your text(?<=#)[^.]+(?=.).*
but those expressions didn't work properly. I'd appreciate your help.
I just tried a simple look behind - #(?<=#).* it will match #google.com you can also group the entire expression and can change it according to single and multi-line matches.
#(?<=#).*

Regex to extract multiple matching string

I am trying to extract HostName and Email address from text file using regex. These fields are optional. It is possible that in some cases only one field is available.
For example: if email address is not available is should extract only hostname and vice versa.
I got nearly working regex. Just not working for single case. see the regex in below link.
regex: ^.*(MAIL:(?<EMAIL>.*))(HOST:(?<HOSTNAME>.*))?
https://regex101.com/r/SDOcIR/1
Note: I am not looking this for specific language.
Thanks
Try Regex: (?:MAIL:(?<EMAIL>[^ ]+))|(?:HOST:(?<HOSTNAME>.*))
Demo

Regular Expressiong - Check Email Address Valid or Value is N/A

I wonder if anyone could make a suggestion how i achieve the following?
I have a regex which suffices in the validation of email addresses which is as follows:
^(\b[A-Za-z0-9._%+-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b)*$
Its a loose validator but as i said, it suffices for what we need. What I need to do if possible is validate on the following criteria:
1) validate email addresses based on the above format
2) if not an email address as above, check if value is N/A or n/a
Appreciate anyones help,
Thanks
Jon
With little modifications to your original expression you can acheive what you wanted...
You can use Or operator to match multiple patterns. (PatternA)|(PatternB)|(PatternC) will match for all three patterns A, B & C. So, below should work.
((\b[A-Za-z0-9._%+-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b))|(N/A)|(n/a)
Or the below should also work
([\w-\._\+%]+#(?:[\w-]+\.)+[\w]{2,6})|(N/A)|(n/a)
Source: http://RegExr.com?3563b
You can try this regex:
^(\b[Nn]\/[Aa]|(?:[A-Za-z0-9._%+-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4})\b)$

How to write a regular expression in c++

I have this string dummy_data:\m192.168.1.125\pApp and I want to extract the IP address from the given string.
I have used the following regular Expression:
\\\\m([\\d\\w\\.]+)\\\\?
This returns \m192.168.1.125, but I want only 192.168.1.125
Do you have any suggestions on how to achieve this?
This one is simple:
[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?
It only works for IPv4 addresses.
This one also worked for your string:
([0-9]{1,3}\.){3}[0-9]{1,3}
I tested both on this random page. I can not tell you how reliable they are.

CAtlRegExp for a regular expression that matches 4 characters max

Short version:
How can I get a regex that matches a#a.aaaa but not a#a.aaaaa using CAtlRegExp ?
Long version:
I'm using CAtlRegExp http://msdn.microsoft.com/en-us/library/k3zs4axe(VS.80).aspx to try to match email addresses. I want to use the regex
^[A-Z0-9._%+-]+#(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$
extracted from here.
But the syntax that CAtlRegExp accepts is different than the one used there. This regex returns the error REPARSE_ERROR_BRACKET_EXPECTED, you can check for yourself using this app: http://www.codeproject.com/KB/string/mfcregex.aspx
Using said app, I created this regex:
^[a-zA-Z0-9\._%\+\-]+#([a-zA-Z0-9-]+\.)+[a-zA-Z]$
But the problem is this matches a#a.aaaaa as valid, I need it to match 4 characters maximum for the op-level domain.
So, how can I get a regex that matches a#a.aaaa but not a#a.aaaaa ?
Try: ^[a-zA-Z0-9\._%\+\-]+#([a-zA-Z0-9-]+\.)+\c\c\c?\c?$
This expression replaces the [A-Z]{2,4} sequence which CAtlRegExp doesn't support with \c\c\c?\c?
\c serves as an abbreviation of [a-zA-Z]. The question marks after the 3rd and 4th \c's indicate they can match either zero or one characters. As a result, this portion of the expression matches 2, 3 or 4 characters, but neither more nor less.
You are trying to match email addresses, a very widely used critical element of internet communication.
To which I would say that this job is best done with the most widely used most correct regex.
Since email address format rules are described by RFC822, it seems useful to do internet searches for something like "RFC822 email regex".
For Perl the answer seems to be easy: use Mail::RFC822::Address: regexp-based address validation
RFC 822 Email Address Parser in PHP
Thus, to achieve the most correct handling of email addresses, one should either locate the most precise regex that there is out somewhere for the particular toolkit (ATL in your case) or - in case there's no suitable existing regex yet - adapt a very precise regex of another toolkit (Perl above seems to be a very complete albeit difficult candidate).
If you're trying to match a specific sub part of email addresses (as seems to be the case given your question), then it probably still makes sense to start with the most up-to-date/correct/universal regex and specifically limit it to the parts that you require.
Perhaps I stated the obvious, but I hope it helped.