Matching characters in different range of values [duplicate] - regex

This question already has answers here:
Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters
(42 answers)
Closed 7 months ago.
I want to make sure my regex match any number from 0-9, any word from a-z, and any of the following characteristics ##$&*:";?! irrespective of when its position in a word or sentence.
If I have ab$2ww3&# my regex will give a positive result but if I have ##he&+#shsj it won't work because there is no number or jbsb2727hd3d won't work because the specific characters I need is not present.
Please I need help on this

Put all the characters you want to match inside a single character class.
[0-9a-z##$&*:";?!]
let input = "asyeb336sheh33";
if (/[0-9a-z##$&*:";?!]/.test(input)) {
console.log('matched');
}
input = "dhd27shs3hj7";
if (/[0-9a-z##$&*:";?!]/.test(input)) {
console.log('matched');
}
input = "##he&+#shsj";
if (/[0-9a-z##$&*:";?!]/.test(input)) {
console.log('matched');
}

Related

RegEx for Dutch ING bankstatement [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
Is there anyone who can help me to get the marked pieces out of this file (see image below) with a regular expression? As you can see, it's difficult because the length is not always the same and the part before my goal is sometimes broken down and sometimes not.
Thank you in advance.
Text:
:61:200106D48,66NDDTEREF//00060100142533
/TRCD/01028/
:86:/EREF/SLDD-0705870-5658387529//MARF/11514814-001//CSID/NL59ZZZ390
373820000//CNTP/NL96ABNA0123456789/ABCANL2A/XXXXXXX123///REMI/UST
D//N00814760/
:61:200106D1840,55NDDTEREF//00060100142534
/TRCD/01028/
:86:/EREF/SLDD-0705869-5658387528//MARF/11514814-001//CSID/NL59ZZZ390
373820000//CNTP/NL96ABNA0123456789/ABCANL2A/XXX123XXXX///REMI/UST
D//N00814759/
:61:200106C236,31NTRFEREF//00060100142535
/TRCD/00100/
:86:/EREF/05881000010520//CNTP/NL19INGB0123456789/ABCBNL2A/XX123XXXX//
/REMI/USTD//KLM REF 1000000022/
The length is not always the same but it does not really matter in your case. You can check for a particular pattern at the end of a string.
(?<=\/\/)([\u2022a-zA-Z0-9]+)(?=\/$)
this regex will look for a string of caracter containing bullet (•), numbers, letters (uppercase and lowercase), that followes two front slash (//) and is followed by a slash (/) and the end of the string ( $ ).
You can test more cases here

Filter a list to find strings which only contain a certain defined set of characters [duplicate]

This question already has an answer here:
find string that consists only of a certain set of characters
(1 answer)
Closed 3 years ago.
I have a list of Japanese words, and a smaller list of characters. I want to search the word list and filter it to find only words that contain characters in my character list, and nothing else. For example, if my word list is the following:
水曜日
火曜日
木曜日
花火
火水
日本語
And my character list is the following:
水
曜
日
火
I only want to return the following words:
水曜日
火曜日
火水
Because the other three words contain characters not on my list.
Currently I'm using a REGEXMATCH formula with the following regex [水|火|曜|日], which captures all words that contain any of the characters, not just the words which only contain those characters.
Is there an easy fix?
^[水火曜日]+$
Ensure that between the start and end of the string, only your selected characters can appear, but can appear as many times as needed.
Demo

Modify this regex expression so that it only accepts characters given with this condition [duplicate]

This question already has answers here:
Including a hyphen in a regex character bracket?
(6 answers)
Closed 3 years ago.
I have a custom validator in my Angular 7 application. I need it to only accept certain characters, however, it is still accepting characters that are not included in my condition.
My custom validator:
static addressFormat(control: AbstractControl): { [key: string]: boolean } {
const isValidAddress = (/^([a-zA-Z0-9,.#-#%&'])([a-zA-Z0-9,.#-#%&'\s/]?)+$/).test(control.value);
return isValidAddress ? null : { addressFormat: true };
}
The first character cannot be an empty space, which is working fine.
After that, the only characters it should accept are the following:
Numbers 0 to 9
Uppercase letters A-Z (you will see the expression accepts lowercase, but ive taken care of that with making each form control value uppercase inside the input tag)
period .
apostrophe '
hyphen -
comma ,
hashtag #
at sign #
percentage %
ampersand &
slash /
spaces
The problem is, I can enter characters like * ) ( + : ; = > < ? and it will consider those valid. How can I modify this validator to make sure those are excluded?
Use this character class. Yours is permitting a range from # to #, rather than just those three individual characters. That's why the bad ones are slipping through:
[-a-zA-Z0-9,.##%&']

Regexp for string stating with a + and having numbers only [duplicate]

This question already has answers here:
Match exact string
(3 answers)
Closed 4 years ago.
I have the following regex for a string which starts by a + and having numbers only:
PatternArticleNumber = $"^(\\+)[0-9]*";
However this allows strings like :
+454545454+4545454
This should not be allowed. Only the 1st character should be a +, others numbers only.
Any idea what may be wrong with my regex?
You can probably workaround this problem by just adding an ending anchor to your regex, i.e. use this:
PatternArticleNumber = $"^(\\+)[0-9]*$";
Demo
The problem with your current pattern is that the ending is open. So, the string +454545454+4545454 might appear to be a match. In fact, that entire string is not a match, but the engine might match the first portion, before the second +, and report a match.

Regex password issue [duplicate]

This question already has answers here:
Regexp Java for password validation
(17 answers)
Closed 8 years ago.
Working on a project where it requires me to have a password field using pattern attribute.
Not really done a lot of regex stuff and was wondering whether someone could help out.
The requirements for the field are as follows:
Can't contain the word "password"
Must be 8-12 in length
Must have 1 upper case
Must have 1 lower case
Must have 1 digit
Now, so far I have the following:
[^(password)].(?=.*[0-9])?=.*[a-zA-Z]).{8,12}
This doesn't work. We can get it so everything else works, apart from the password string being matched.
Thanks in advance,
Andy
EDIT: the method we've used now (nested in comments below) is:
^(?!.*(P|p)(A|a)(S|s)(S|s)(W|w)(O|o)(R|r)(D|d)).(?=.*\d)(?=.*[a-zA-Z]).{8,12}$
Thanks for the help
Use a series of anchored look aheads for the :must contain" criteria:
^(?!.*(?i)password)(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,12}$
I've added the "ignore case" switch (?i) to the "password" requirement, so it will reject `the word no matter the case of the letters.
This regex should to the job:
^(?!.*password)(?=.*\d)(?=.*[A-Z])(?=.*[a-z]).{8,12}$
it will match:
^ // from the beginning of the input
(?!.*password) // negative lookbehind whether the text contains password
(?=.*\d+) // positive lookahead for at least one digit
(?=.*[A-Z]+) // positive lookahead for at least one uppercase letter
(?=.*[a-z]+) // positive lookahead for at least one lowercase letter
.{8,12} // length of the input is between 8 and 12 characters
$
Link to phpliveregex
Try This:
^(?!.*password)(?=.*[A-Z])(?=.*[0-9])(?=.*[a-z]).{8,12}$
Explanation
^ Start anchor
(?=.*[A-Z]) Ensure string has one uppercase letter
(?=.*[0-9]) Ensure string has one digits.
(?=.*[a-z]) Ensure string has one lowercase letter
{8,12} Ensure string is of length 8 - 12.
(?!.*password) Not of word password
$ End anchor.
Try this way
Public void validation()
string xxxx = "Aa1qqqqqq";
if (xxxx.ToUpper().Contains("password") || !(xxxx.Length <= 12 & xxxx.Length >= 8) || !IsMatch(xxxx, "(?=.*[A-Z])") || !IsMatch(xxxx, "(?=.*[a-z])") || !IsMatch(xxxx, "(?=.*[0-9])"))
{
throw new System.ArgumentException("Your error message here", "Password");
}
}
public bool IsMatch(string input, string pattern)
{
Match xx = Regex.Match(input, pattern);
return xx.Success;
}