Regex to match email id's in javascript? - regex

Lets say I have something like this:
vin#text.com
jay#text.com
text#text.com
All these id's belong to #text.com, and I want to match just that, whether an id has a
#text.com
or not
for example:
vin#gmail.com is invalid
while
vin#text.com is valid
but
vin#text.com.com , vin#text.com#text.com are both invalid
there should not be any characters after #text.com but there can be as many as possible in the beginning

So, text.com can be treated as required after # for your scenario.
Simple regex could be
^[a-zA-Z0-9+_.-]+#text.com+$
Please have a look if this works for you.
Happy Coding!

Related

Regular Expressions - Exclude characters

I am trying to use regulare expressions with a formvalidator.net to validate a form but I am struggling to under stand regular expressions,I have had a look at some websites but it is still baffling.
Basically I want to validate a field so that when a user enter something it will chack that the word or entry doesnt contain certain characters. So for example I don't want '!name' or 'this ! name' to be accepted.
using regexp for testing I have created this expression ([a-zA-Z\+\&\,\.\-\(\)\d][^<>%$!]+) which excludes those characters but in my form validator it will still accept '!name' or 'this ! name'
Can anyone point me in the right direction? I feel like I'm typing stuff in and gettign nowhere.
Ian
Basically I think you want to either decide what characters you don't want OR what characters you do. Not both.
I think this is what your after:
^[^<>%$!]+$
See it working here

Regex that matches a pattern only if string does not begin with 'N'

I need to put together a regex that matches a patter only if string does not begin with 'N'.
Here is my pattern so far [A-E]+[-+]?.
Now I want to make sure that it does not match something like:
N\A
NA
NB+
NB-
NCAB
This is for REGEXP_SUBSTR command in Oracle SQL DB
UPDATE
It looks like I should have been more specific, sorry
I want to extract from a string [A-E]+[-+]? but if the string also matches ^(N|n) then I want my regex to return nothing.
See examples below:
String Returns
N/A
F1/AAA AAA
NABC
FABC ABC
To match a character between A and E not preceded by N, you can use:
([^N]|^)[A-E]+
If you want to avoid fields that contains N[A-E] use a negation in your query using the pattern N[A-E] (in other words, use two predicates, this one to exclude NA and the first to find A)
To be more clear:
WHERE NOT REGEXP_LIKE(coln, 'N[A-E]') AND REGEXP_LIKE(coln, '[A-E]')
Ok I figured it out, I broadened the scope of the problem a little, I realized that I can also play with other parameters of REGEXP_SUBSTR in this case that I can have returned only second substring.
REGEXP_SUBSTR(field1, '^([^NA-D][^A-D]*)?([A-D]+[-+]?)',1,1,'i',2)
I still have to give you guys the credit, lot of good ideas that led me to here.
Just throw a [^N]? in front. That should do it.
OOPS...
That actually needs to include an " OR ^ "...
It should look like this:
([^N]|^)[A-E]+[-+]?
Sorry about that...It looks like the right answer already got posted anyway.

in regex get a single match just before the match pattern?

I have a response like below
{"id":9,"announcementName":"Test","announcementText":"<p>TestAssertion</p>\n","effectiveStartDate":"03/01/2016","effectiveEndDate":"03/02/2016","updatedDate":"02/29/2016","status":"Active","moduleName":"Individual Portal"}
{"id":103,"announcementName":"d3mgcwtqhdu8003","announcementText":"<p>This announcement is a test announcement”,"effectiveStartDate":"03/01/2016","effectiveEndDate":"03/02/2016","updatedDate":"02/29/2016","status":"Active","moduleName":"Individual Portal"}
{"id":113,"announcementName":"asdfrtwju3f5gh7f21","announcementText":"<p>This announcement is a test announcement”,"effectiveStartDate":"03/02/2016","effectiveEndDate":"03/03/2016","updatedDate":"02/29/2016","status":"InActive","moduleName":"Individual Portal"}
I am trying get the value of id (103) of announcementName d3mgcwtqhdu8003.
I am using below regEx pattern to get the id
"id":(.*?),"announcementName":"${announcementName}","announcementText":"
But it is matching everything from the first id to the announcementName. and returning
9,"announcementName":"Test","announcementText":"<p>TestAssertion</p>\n","effectiveStartDate":"03/01/2016","effectiveEndDate":"03/02/2016","updatedDate":"02/29/2016","status":"Active","moduleName":"Individual Portal"}
{"id":103,"announcementName":"d3mgcwtqhdu8003","announcementText":
But I want to match only from the id just before the required announcementName.
How can I do this in RegEx . Can someone please help me on this ?
As an answer here as well. Either use appropriate JSON functions, if not, a simple regex like:
"id":(\d+)
will probably do as the IDs are numeric.

fetch email address that does not contain certain words from webpage

Please tell me how can I extract emails (1st match) that does not contain words 'ajax' and 'gif' within email address. Here's the basic regex that I have:
match = re.findall('([\w.-]+#[\w.-]+\.\w+)', q.read(), re.I)[0]
Thanks,
I think you want something like this,
\b(?!\S*(?:ajax|gif)\S*)([\w.-]+#[\w.-]+\.\w+)\b
DEMO

regular expression attribute in MVC3

How can I use regular expression attribute in MVC3 on EMAIL field to give an error message if the email entered contains no-email.com?
The exact syntax will depend on the language you are using and possibly the method you are using. These examples should help.
You wouldn't normally need a regular expression to match a simple string.
But, if for some reason, it has to be regex, you would just need to escape the hyphen and dot. Like so:
no\-email\.com
Depending on what you are doing, you may need to match the rest of the email address:
(.*?)no\-email\.com
You may also want to tie "no-email.com" to the end of the string, like so:
(.*?)no\-email\.com$
If you also want to match the # sign to the domain name, do:
(.*?)#no\-email\.com$