I need to verify a password using reqex. I have written one and tested it in this checker and it works: http://www.nvcc.edu/home/drodgers/ceu/resources/test_regexp.asp
But when I add it to my Java application, it fails.
Regex in regex checker:(\D+)(\d+)(\D+)(.*)
Regex in java: (\\D+)(\\d+)(\\D+)(.*)
Test string: 1Hello2
This passes in the online checker but fails in Java.
Does anyone know why?
I want the regex to match any password that has a number in its middle (can have them at the start and end too).
I need 2 seperate regex: one that matches digits in the middle (pass1word or 1pass1word or 1pass1word) and also a regex that matches a digit at the start or end (1password or password1 NOT pass1word1 because that is in the string category).
\Dmeans a non-digit character. To match anything with a number in the middle, use something like'.+\d+.*'..*\d.*.1hellofor example, although it's a valid password according to OP.'.+\d.+'(too late to edit the first comment now). Your regex matches any password with a digit in it. Mine matches any with a digit in the middle, which is how I understand the last sentence of the question.