Multiple email seperated by semicolon regex [duplicate] - javascript

This question already has answers here:
Regex for validating multiple E-Mail-Addresses
(11 answers)
Closed 4 years ago.
Hi guys i have a requirement such that i have to validate email addresses seperated by semicolon.For example "test#test.com; test#Tes.com" something like this.I am using the below regex :
(([^#]+#[^\s#]+\.[^\s#;]{2,}\;{0,1}\s*))+
The problem here it the regex works even if there is no semicolon in between but with space eg "test#test.com Test#tes.com".But That is not correct.so can anyone tell me how to achieve this?Also when there is a single email id no need of semi-colon in between

found a working regex. Tested till 3 emails.
([^#]+#[^\s#]+.[^\s#;]{2,})+(\;([^#]+#[^\s#]+.[^\s#;]{2,}){1,1})*
Tested samples :
test#test.com;sample#google.com;dsdsd#dsd.sd -> true
test#test.com;sample#google.com dsdsd#dsd.sd -> false
test#test.com -> true
test#test.com; -> false
Key thing here is to follow \w+(.\w+)+ pattern.
Hope this helps

Try regex (?!.*;$)^([-\w]+?#\w+\.\w+(?:\s*;\s*)?)+$
This will match any no. of emails separated by a semicolon. The negative lookahead
(?!.*;$) will not match email with a semicolon at last.
Regex

Related

How to check the sting is alphanumeric or not in peggyjs [duplicate]

This question already has answers here:
RegEx for Javascript to allow only alphanumeric
(22 answers)
Closed 1 year ago.
I want to check the given string is alphanumeric or not. i.e. the expected output is as follows
123 should retun false
abc should retun false
a123 should retun true
1a23 should retun true
I tried with the ^[a-zA-Z0-9]*$ regex. It is not working as expected. Can anyone suggest the working peggyjs regex? Thanks.
You can assert not only digits, and match at least a single digit restricticting to match to only a-z or a digit.
Using a case insensitive match:
^(?!\d+$)[a-z]*\d[a-z\d]*$
Regex demo
If you know the order (letters then numbers for example) you can do .*[a-zA-Z].*[0-9]
But I assume you can't make such assumptions so I would use the slightly more complex ^(?=.*[a-zA-Z])(?=.*[0-9]).* which means "a letter somewhere later, and also a number somewhere later".
PS : you can replace all [0-9] by \d if you like.
Edit : that's only assuming you don't get other kinds of characters, use Alireza's regex instead if you need to.

Remove single quotes and last comma in jquery string using Regex [duplicate]

This question already has answers here:
JavaScript REGEX Match all and replace
(2 answers)
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I have a data
'abc','def','ghi',
I want to remove the single quote on all character and want to remove only the last comma, example like below
abc,def,ghi
How would i achieve that using regex for javascript?
I tried using this regex
.replace(^\'|,\s*$,"");
But seems like it is only removing the first quote as shown below
abc','def','ghi',
I am not very good in regex, i appreciate any help that i can get. Thanks
try this:
.replace(/\'|,$/g, "");
the ^ at the beggining made the regexp to only match the quote at the beggining of the string, also you have to add the g to keep looking after the first match
There is an easy way, use the $ operator
.replace(/'|,$/g, '')
Can you please check replace(/'|(,)$/g," ") and it should work.

Confusing regex. I can't understand this part: +$/ [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 4 years ago.
I was doing a hackerrank here and I did the following code:
/^(Mr\.|Mrs\.|Ms\.|Dr\.|Er\.)\w/
But the answer was
/^(Mr\.|Mrs\.|Ms\.|Dr\.|Er\.)\w+$/
and I don't understand the last part of that regex. What is it?
Here, \w will select An alphanumeric character (“word character”), and When you put a plus sign (+) after something in a regular expression, it indicates that the element may be repeated more than once.
Thus, /\w+/ matches one or more alphanumeric characters.
And $ here means End of string.
Example 1 --- /^(Mr\.|Mrs\.|Ms\.|Dr\.|Er\.)\w$/.test('Mr.J'); // true
Example 2 --- /^(Mr\.|Mrs\.|Ms\.|Dr\.|Er\.)\w$/.test('Mr.Joseph'); // false
Example 3 --- /^(Mr\.|Mrs\.|Ms\.|Dr\.|Er\.)\w+$/.test('Mr.Joseph'); // true

Regex query, description [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 5 years ago.
I have a regex query for password verification, the rules are password must be between 8-15 chars, 1number + 1 special characters. It is working perfectly in web form.
I only need to understand it fully. If anyone can help me in describing this regex group by group,, it will be of great help to me. I do understand some part but not all.
^(?=.*[0-9])(?=.*[!##$%^&*])[a-zA-Z0-9!##$%^&*]{7,15}$
Since you updated the regex...
^(?=.*[0-9])(?=.*[!##$%^&*])[a-zA-Z0-9!##$%^&*]{7,15}$
^(?=.*[0-9]) from the start of the string, match any numbers. The lookahead ?= prevents the regex from continuing if nothing matches.
(?=.*[!##$%^&*]) match any special characters in the group.
[a-zA-Z0-9!##$%^&*] capture all letters, numbers, and special characters. At least 7 and up to 15 until the end of the line.

How to fix my regex? [duplicate]

This question already has answers here:
Matching a Forward Slash with a regex
(9 answers)
Closed 8 years ago.
I tried making a regex expression to search for in the string named 'patt'. Unfortunately the following gives an error in dreamweaver:
patt.search(/.*://.*waw\d.omegle.com/);
I need to get this pattern working. What am i doing wrong here?
You need to escape the / in the pattern as
patt.search(/.*:\/\/.*waw\d\.omegle\.com/);
Also escape . for more saftey as . alone could match anything in regex
Example
var patt = "http://asdfwaw1.omegle.com";
patt.search(/.*\/\/.*waw\d\.omegle\.com/);
=> True
because it thinks the / in // is the end of the reg exp. If you look at the coloring in your code above you can see the brown color ends at the first slash. You need to escape it.
/.*:\/\/.*waw\d.omegle.com/;

Categories

Resources