We are trying to scan the list of files for the password. As per our requirement, password should contain alphanumeric with special character.
Please help me with why this regex is not working
((\w*)([$%*@#]+)(\w+)){10,}
Note: I will be using this regex in Linux environment
Conditions to match:
1) Minimum 10 character
2) Should contain 1 special character
3) Should contain 1 Numerical character
4) should contain 1 Alphabetic character
Your regex is matching firstly zero or many word characters
(\w*), then at least one but possibly many special characters([$%*@#]+), then at least one but possibly many word characters(\w+). Whatever that matches, you're then attempting to match that exact same string at least 10 times(...){10,}. So, for example, you could haveabc$%defwhich would match the outermost parantheses, but to match the full expression you'd then need that string repeated at least 10 times, like thisabc$%defabc$%defabc$%defabc$%defabc$%defabc$%defabc$%defabc$%defabc$%defabc$%defI doubt this is what you're after :)
It's quite hard to understand exactly what the requirement is, but it looks like there are a few possibilities:
Match a string of 10 characters which are a mixture of alphanumeric and certain special characters. This is quite a simple one, and a regex to achieve this might be as follows:
The problem with the above is that it does not require a special character to always be present.
The key part might be that there must be at least on special character within a password of exactly 10 digits. To achieve this, you could do something like this:
This works as follows - we know that there must be at least one special character, and we know that the password is 10 characters long. Therefore, there can be between 0 and 9 consecutive
\wcharacters initially. After that, there MUST be a special character. Then, after that special character, there can be either\wcharacters OR special characters. The above regex does not enforce the exact length of 10 characters however.To achieve the exact length, you might have to be explicit about the lengths, which may start getting messy. For example:
In essence here we are using many regular expressions for each of the combinations of lengths of the particular parts of the expression - e.g.,
\w{4}[$&*@#][\w$&*@#]{5}would be the case of matching exactly four\wcharacters, then a special one, then five word or special characters.You may also want to consider whether a two-stage process would work better in this instance. You could go with a simple imperfect example which includes results without special characters (my first example), and then query the resulting set to filter only the passwords which do indeed contain at least one of the special characters.
A bit more detail around the exact rules would certainly be helpful.