I need to create a regex which contains at least 1 special character, and at least 1 number with alphabets.
            Asked
            
        
        
            Active
            
        
            Viewed 475 times
        
    -2
            
            
        - 
                    Could please give example strings, which should be matched by your regex ? – Aedvald Tseh Jan 04 '18 at 04:46
1 Answers
0
            
            
        You may try the following pattern:
^(?=.*[0-9])(?=.*[^A-Za-z0-9])(?=.*[A-Za-z]).*$
Explanation:
(?=.*[0-9])          assert one number present
(?=.*[^A-Za-z0-9])   assert one special character present
(?=.*[A-Za-z])       assert one alpha present
Note that I have defined a special character as being anything not alphanumeric. If instead you have a list of special characters, then you can modify the middle lookahead in my pattern.
 
    
    
        Tim Biegeleisen
        
- 502,043
- 27
- 286
- 360
- 
                    If special characters are a smaller list I think you'll need to change the final `.*` as well to avoid invalid matches. – CRD Jan 04 '18 at 05:03
