5 kyu
Regex Password Validation
16,104 of 29,078EricFreeman
Loading description...
Regular Expressions
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Something new that I learnt.
Wow. Learned so much!
the test give me all false, but in my VSC the same code give me the correct answer... whats wrong with this kata?
Why do you think something is wrong with the kata, and not with your solution?
Why do you ask this question when your PP is the because?
This comment has been deleted.
Well, your response sounds similar to this story:
Of course, the exam and the teacher is not to be blamed, but the person not trained or didn't dive deeper enough into the materials. This applies to what you have as well. To you it is fine in your machine, with your tests and what you think the strings would be. But deep down, strings can come in many forms that you haven't thought of and your regex failed to handle those said strings. Now, it is back to you whether you want to fix it or nah. The strings are shown to you in the tests. You can add those said failed strings to your local tests assertion.
This comment has been deleted.
Do you know what regex means? It's short for regular expression. Google that. And in this kata you should only write the regex inside those quotes and nothing more.
ive never used regex in my life eye opener
There were two testcases that were logging false instead of true. That changed when I removed the global tag
see here
Thanks
Not sure if this should be considered a spoiler, but thanks, that solved my issue
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting#post-discourse and use code block formatting next time.
See the initial code, you only need to write a regular expression, not a function:
Java translation (author inactive)
What shold I do, if it says True, should equal False, even if I print(False)?
You must return the value, not print it (what you print is not taken in consideration by the tests, this is just to help you debugging your code.
Even if I return False, it writes True should equal False, if I test my code not in codewars, it works, but when I test it there, it doesn't work
Sorry I misread your code and forgot this kata didn't use a function. The point of this kata is to assign to
regex
a regular expression as a string literal that validates a password according to the description's requirements. Your code should just be something likeregex="SOME REGULAR EXPRESSION"
. If you are not familiar with regular expression, it's more reasonable to learn about it on easier katas. You can make a research with theRegular expressions
tag inPractice
.This comment has been hidden.
Have you read there that everything that matches that regex is an invalid password? Here your regex should match valid passwords. And because you only write the regex, you can't reverse the result to use it.
C# translation ready! Please review and approve.
you already opened a suggestion for this one here. Same remark as last time: in this kata, the user should assign a regexp to a variable (a
const
or astatic readonly
class field in C#). The initial code should not contain a function.TypeScript translation (literal translation of JavaScript; not much point for the obvious reason, other than allowing this kata to show up for thos who train on TypeScript but not on JavaScript)
Approved by someone
When I test the code here, it says I failed the test saying True should equal False, but when I run the test cases on my own it works perfectly fine. How do I fix this? Its on python BTW.
This comment has been hidden.
im getting a name error 'regex' is not defined in the test cases. any solutions?
Easy, little challenging, yet a real-world example.
(Python) Testing with the search function (as opposed to match, for instance) is kind of weird, as it forces you to insert the beginning-of-line anchor. It might be good as a challenge (forcing you to look at the test code for once) but doesn't really correspond to best practices as I know them: When you use a regex for verification, you almost always use re.match (or even re.fullmatch, though that is rarer, seemingly).
replaced with
re.fullmatch
This comment has been hidden.
This comment has been hidden.
Read this: https://www.codewars.com/kata/52e1476c8147a7547a000811/discuss/javascript#633833d2b57f7b006450f99a
You are missing * from ?=.*
It's not missing, you can't see it because markdown formatting wasn't used.
This comment has been hidden.
REGEXP
should be aRegExp
object, currently you have aString
.Thank you!
The regex function I wrote in Python is working on every value i try manually on my IDE but i can't get to make it work in CodeWars.. As if the tests aren't working. Any help?
I rather write a function that reads the string. Seems more readable than a complicated regex...
Worth noting that performing this action on passwords is against best practise guidelines
It could still be a useful regex practise - just don't do this as part of real password validation
https://github.com/OWASP/ASVS/blob/v4.0.3/4.0/en/0x11-V2-Authentication.md
V2.1 Password Security
2.1.9
It was hard for me cause I didn't know regex but I finished it and I'm happy. It was great.
i did it but not entirely satisfied, coz i need to have a better understanding, where can i learn more about regex in python ? anybody, please?
https://realpython.com/regex-python/
Thanks,
Youtube, for sure.
This comment has been hidden.
This comment has been hidden.
random tests not working
They do:
Why are you using flags? Read the posts below: https://www.codewars.com/kata/52e1476c8147a7547a000811/discuss/javascript#633833d2b57f7b006450f99a
Thank you Chrono79. It works with me now.
Ruby translation with upgrade to MRI 3.0
rejected for changing the setup from a variable to a function
This comment has been hidden.
Agree
This comment has been hidden.
You shouldn't write a function, you should only write the regular expression. Sites like regex101.com could help.
Okay, thx! I found a solution an regex101.com was very helpful!
Hi,
I'm doing the kata using Javascript and I'm not sure why but all the random tests seem to not work for me for some reason. However if I run the same strings in regex101.com (with correct regex flavor selected) it does match the string just fine. Any ideas on how to troubleshoot issues like this?
You are using the global (
g
) flag; it changes the behavior of RegExp.test()Asking for help is not a kata issue btw ;-)
Ótimo kata.
help, im a new joinee and dont know how to generate the output. usually there's a def: block and we use a return statement. how do i return output here?
This kata is different. Write the regular expression inside the quotes:
You don't need to import re or write something else. The tests take care of that.
tysm ( i dont really get what you mean but still thanks, i'll check on this later)
I'm pretty sure this kata is broken. I tested my regexp in RegExr and the tests that this kata says I am failing are succeeding there so... Not really sure what's going on
Neither are we, because you provided no meaningful information.
What's sure is that the kata isn't broken, and the mistake is in your code.
See if there's something helpful in this article https://docs.codewars.com/training/troubleshooting
There is indeed some problem, with his regexp, if you copy and paste the test that fails to sample tests it works fine. Can't find why tho.
I found the issue, the global
g
flag has a special meaning in the methodRegExp.test()
which is used by the tests suite; it makes theRegExp
object remember the last match position to start from it in the next call. this means thatRegExp.test()
will return a different result if you call it several times in a row on the same string, e.g. :MDN ref
Broken kata!!
My code is normaly working on my PC. But here... 2/3 of basic tests is wrong. Why?
How could we know? Please read this if you want something helpful to be feasible for you: https://docs.codewars.com/training/troubleshooting/
You can see which input makes your code fail, try that input in your PC, it'll fail there too.
I checked every basic test with my hands - I got right answers... :(
It fails with inputs like this:
'9aYKIm?GkfCJUr02G'
I got 'False' in my Jupiter Notebook. It is expected - this string have '?'.
Now, before your regex was lacking something. Write the regular expression inside the quotes:
You don't need to import
re
or write something else.Without 'import re'??? Can it work??? Without 'compile' and 'match'? Hmmm... Probably, i don't fully understand, how does regex work...
The tests do that part for you:
compile
is not necessary.Oh, thanks. It seems, I have written some extra things.
Shell version should be modified to use a regexp
echo
ed by the user, so as to align with the other languages.(Unless it's possible to directly retrieve a variable set by the user ? the test framework is not documented anywhere ...)
Python, possibly other languages: tests miss sanity checks on values provided by user solution and crash badly when an unexpected value (not a pattern, or not a valid pattern) is returned.
This comment has been hidden.
Oh my God, it's my first task with reg. and I only needed 3 cups of coffee, almost 4 hours of re-reading doc, 100 times of debugging... And finally i did it! Although I understand that this kata like a piece of cake (if uk reg), but I'm still happy as a clam that I did it! it's a good experience. So, I'm going to coffee!!!
This comment has been hidden.
This comment has been hidden.
I know there is a strong tendancy (with which I personnally disagree in most cases since it just encourages the stagnation and the maintainment of badly specified katas or strong divergencies between languages) to avoid massive invalidation of solutions, but here I believe we have a clear case: the JS tests just don't respect the specifications of the kata (
You need to write regex that will validate a password
). I suppport your suggestion to make the test a regex and not a function.Note: there is the same problem in Shell, but I have no idea if it's possible to use a regex echoed by user (or just collect a variable directly in the tests).
here is a complete rewrite, with Node 14, testing a regexp as a variable, random tests, description updated to stop the endless questions about
'_'
I agree with your point, but it is not a big deal. A simple google search will yield the regex for this. The difficulty of the problem will not change even if you force the user to write regex. I used regex to solve this one but I didn't do it in one line. Atleast people can attack the problem in different ways now without worrying about conventions.
somebody approved my fork and there are many solutions already, so i'm closing this to open an
issue
for ShellThe task caused a lot of pain, but I became smarter
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This is my first experience with regular expressions, and I don't understand this kata. I have seen some comments stating that you must simply assign a regular expression to the regex = "" that the kata begins with in the console. But when I fill it out with something like regex = re.search('aeiou', string), I don't know what I'm supposed to pass as the string value. Can someone please help me with the syntax here?
edit: I'm solving this kata in Python
This is the initial code for Python:
You only write the regular expresion between the quotes, nothing more.
This comment has been hidden.
Thank you, I think I get what I need to do now. I need to figure out a regular expression using the regex metacharacters that will return True for a valid password
you don't have to do anything other than provide the regex
Not your usual kata, but great experience with learning about regular expressions.
I can not check existance of non-alphabetic chars. any suggestions?
Regexes can do that. Read the documentation about regexes in your languages.
thanks. actually I should change my point of view. I only checked the alphanumeric instead of trying to find non-alphabetic in the string.
Fairly new to coding and regex. I was able to pass the test but my submission attempts failed. Is there a way to get more feedback other than "expected false?" It is very difficult to troubleshoot when I don't know which attempt is causing my code to fail. I learned a lot about regex today using youtube and stackoverflow but hate that I can't identify my mistake(s). I am probably overlooking some feedback feature. TIA
you can log the input to the console and see whats going wrong
Thanks Siddharth114, the problem is that I don't know what input argument the test function is using so I can't test in the console. The example tests that are provided all come back as passed, it is only when I try to submit that I get a failed notification. I also used https://regexr.com/ to make sure my expression was working for the examples. In other Kata, I can see a list of tests and results when I make an attempt, this one just tells me that it expected flase without letting me know the argument that was used for the test function.
This comment has been hidden.
Here's an example of a test:
Your code should contain only one line: assignment to
regex
variable.This comment has been hidden.
Just make sure your password don't have space or semicolon or some other special characters.
Not a suggestion prior to the kata ~~
it's for the coders
Broken kata
Great proof provided...
No, not broken.
This comment has been hidden.
Print the input: https://docs.codewars.com/training/troubleshooting/#print-input
This comment has been hidden.
Please use spoiler flag next time.
C# translation ready! Please review and approve.
rejected for not enforcing the use of a regexp
Hi, guys.
Kata not work?
p.s. my code is faild on first test(in full test suite), but in VS this test, and all tests are passed(watched the tests in sample)
Read this, please: https://docs.codewars.com/training/troubleshooting/
It works:
Yep, you are right. Thank you.
This kata is so useful!
This comment has been hidden.
yes, but that should be stated in the bullet list. as it is written now, it could be misinterpreted as "only alphanumeric passwords will be passed to your function" i think the tricky part of a kata should not be in the ambugiuity of the wording
This comment has been hidden.
Terrible kata
Could you elaborate?
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Well... no? I see 2 failing in sample tests alone.
Your first lookahead isn't correct (but the last one is)
OP solved it, closing
This comment has been hidden.
STDERR Traceback (most recent call last): File "tests.py", line 5, in test.assert_equals(bool(search(regex, 'fjd3IR9')), True) File "/usr/local/lib/python3.8/re.py", line 201, in search return _compile(pattern, flags).search(string) File "/usr/local/lib/python3.8/re.py", line 303, in _compile raise TypeError("first argument must be string or compiled pattern") TypeError: first argument must be string or compiled pattern
That's the error that I get when trying to test my code. Function wasn't predefined when I was starting. Only had regex = "" in my console. Can anyone help with this? Checked the code in VS Code, works as expected
There's no function here, you only need to write the regular expression.
This comment has been hidden.
I was talking about Python there, in Ruby simply write
regex=/your regular expression here/
so, from your code, remove the quotes.Thanks man! It works!
I can't test my expresion. Using Chrono79 simple example of regex="[0-9]", in Ruby 2.5 it shows this error:
on main.rb:6:in =~': type mismatch: String given (TypeError)
But my attempt is in line 1, any idea of why it can be?You're supposed to write a regular expression. Not an issue.
what is the syantax? def is not prewritten
No, you only need to write the regular expression between the quotes:
give me one example. how can i write, if there is a str quote("")
That'll match any digit in a string. The regular expression you have to write here is more complex than that, but you get the idea. You can also use regex101 to fiddle and try different things, make sure you select Python at the left.
This comment has been hidden.
return
Great one. I completely forgot regular expressions since school. :)
Don't know what wrong in my code
We dont know either without being able to see your code
This comment has been hidden.
Not necessarily the case due to different version and packages installed between your IDE && CW language. Read this for more info && use
question
label next time.Ruby 3.0 should be enabled.
so, it seems that for 3.0 the runner moved away from concatenation of preloaded + solution + tests in favor of 3 different files (
preloaded.rb
,solution.rb
,test.rb
).This seems to cause a problem for upgrading this specific kata to Ruby 3.0: the kata requires a variable named
regex
insolution.rb
. In Ruby, variables that start with a lowercase letter are locals, and do not get exported, so the tests cannot findregex
...Regex
(a constant) or$regex
(a global) would work, but this would invalidate all the current solutions :/I do not know Ruby, does someone know a way around this ?
You might be interested in this discussion.
What a terribe kata
This comment has been hidden.
Not a kata issue as expected code behaviour from your IDE != from CW due to theifferent version and packages installed between your IDE && CW language. Read this for more info && use
question
label next time.Passed all the tests and at the moment I clicked attempt, throw 3 errors... How can I see the failed ones?
In javascript? Use
console.log()
https://docs.codewars.com/training/troubleshooting/#print-input^^
Hello
I have tried my regular expression and all passed in test.
I found a mistake that in tests before most of the validations there is a "!" character.
Please help in order to solve this kata.
Cheers, António Pedro
That's not a mistake, that means that test expects
false
. Read this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOTThis comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/#print-input
The tests are ok.
Perl power!
Shell clearly is the most powerful CW language...
so, this was more of a riddle as a IRL RegExp requirement, i mean, at least mostly, right? please somebody say yes? i love regex stuff, but this one almost made me crazy
This comment has been hidden.
This comment has been hidden.
You're logging one thing and returning another.
Thanks for your help I figured it out :) I also had other problems
This comment has been hidden.
Not a kata issue, please read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#print-input
2 random tests are failed in JS and I do not know why. Can anyone help me?
Some tests are not working For example the password 4fdg5Fj3 is a valid password but the test expect False.
No, you're reading the logs wrong. The test with that input expects
True
, the previous and next one expectFalse
. The log appears above the test result: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#print-inputThis comment has been hidden.
'_'
is not alphanumeric in Python :This comment has been hidden.
This comment has been hidden.
That's a problem with your code, not a kata issue. Please read how to properly report an issue: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
Yeah, sorry about that, found the problem with my code.
This comment has been hidden.
You have to write your regular expresion between those quotes.
This comment has been hidden.
Throws 2 falses no matter what in JavaScript, all tests passed.
Suggesting for people to very carefully review this Rust translation.
There is a Regex crate for Rust in codewars, but that crate doesn't support "lookahead". That might sort of go against the challange of a oneliner Regex. You can still solve this with Regex, just no lookahead.
rejected for not enforcing the use of a regexp
This comment has been hidden.
Not a kata issue, your regex fails tests like this one:
And because it's failing random tests, the number of tests it fails is random too.
it failed on 'NmIm5EQDNF7R1_ar', 'KFPYe// FrZvdu4o', 'Y AR2ECbjqCYKSJ' etc. too. Not sure whats wrong, I literally stated learning about regex from an 1 hour ago, looks like I need to learn more. O_o
*edit* nevermind I got the issue, btw thanks
For 1 hour into regex, you're pretty close to the right one. This site can be useful: https://regex101.com/
Thank Youuuuuuuuuuuuu very much :))))))
This comment has been hidden.
Because it's wrong, paste it here: https://regex101.com/ and see what it matches and what it means.
The attempt show a test fail no matter what, when I tested it on sample it was working as expected
Which language? In javascript you can print the input and check why your code fails.
yes in javascript, I printed the input and used that in test and that works but apparently it doesn't work on attempt
Test.expect(!validate('fjd3 IR9'), 'fjd3 IR9 - Expected false') works fine in test but not when I attempt
The test is ok, read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#post-discourse Are you sure, that's the test you're failing? The log appears above the test result.
Remember to close the issue next time when you pass the kata and it wasn't an issue.
I want to know if the validate is supposed to have an '!'(in '!validate') because the ones expected to be true are turned false for no matter solution you try but if you add it the answer gets validated. Test.expect(validate('djI38D55'), 'djI38D55 - Expected true'); // Doesn't work Test.expect(!validate('a2.d412'), 'a2.d412 - Expected false'); // Works
Test.expect(!validate('djI38D55'), 'djI38D55 - Expected true'); // Works Test.expect(!validate('a2.d412'), 'a2.d412 - Expected false'); // Works
Problem solved after a lot of work. :)
Same here I just wasn't paying enough attention to my solutions' logic NOTE: NOTHING IS WRONG WITH THE KATA ITSELF(this is just for future people who will struggle with it)
Tests in Python and JS are inconsistent
JS needs random tests.
fixed
This comment has been hidden.
https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#how-can-i-see-which-input-causes-my-solution-to-fail
In this particular kata, you can't print the input in Python, but in javascript you can.
a more obvious hint please?? :'(
This comment has been hidden.
Write
console.log(password);
as the first line of your function, check why your function returns true when it shouldn't. You can use regex101 to test your regular expression.This comment has been hidden.
Your code is wrong
your supposed to write a regex line in the string:
regex =
to validate the passwordbut how the code can be wrong if in my ide it gives the correct 'True' and here not and i dont know what u mean by 'write a regex line in the string: regex = to validate the password' i have wrote it like that regex = ""
The main problem is in your if- else statement. Give a close look at the problem statement, it says that the password should be
atleast
6 characters. I hope you got your error.The main problem is in your if- else statement. Give a close look at the problem statement, it says that the password should be
atleast
6 characters. I hope you got your error.This comment has been hidden.
It's possible, and there are many reasons, and usually it's because user does something wrong. We could check if you shared your code with us (see here how: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#how-do-i-post-to-a-kata-discourse)
This comment has been hidden.
Please, use markdown formatting and mark your post as having spoiler content next time (those things are in the link hobovsky shared before).
In Python, you only have to write a regular expression inside the quotes:
This comment has been hidden.
Only alphanumeric characters allowed.
This comment has been hidden.
This comment has been hidden.
OP solved it, closing
This comment has been hidden.
Remember that
\w
symbol allows _ characters along with alphanumeric characters. So, when you are diminishing the scope of its complement by using\W
that means that you are also allowing the_
symbol as valid. This is one of the problems in your code. So, I would suggest you to allow only the alphanumeric characters instead of diminishing the scope of any characters or symbols.This comment has been hidden.
It may be helpful to mark the start and end of you regex. You also shouldn't use the 'thing' to check for actual characters.
This comment has been hidden.
What's your regex? Don't forget to use spoiler flag.
This comment has been hidden.
2 problems with it:
I hope this helps.
This comment has been hidden.
The top of my code says regex = "" and then I define my function as def password(regex) How do I get the input the author is meaning to give? The test cases all work in my IDE but I output the same answer (false) for the test cases here.
You write a regex pattern, like
regex = ""
. Then, usingre
the author tests if your regex pattern validates the pattern or not. By the way, you don't define a function.Ok I'm very new and I don't under understand regex. I thought I just had to create a function to validate a password based on the requirements. I tried reading the python re page but I didn't quite get it. Could you briefly explain it to me?
Well maybe do some 8kyus and 7kyu regex. Then, use some sources(Stack Overflow or Geeks for Geeks are both fine). Also, look at different peoples solutions.
This comment has been hidden.
There's a small mistake in your regex.
Ahh i see, I just needed to throughly read the documentation after stepping away for a second. Thanks again!
This comment has been hidden.
Because that matches any portion of the string.
This comment has been hidden.
Well, there's that problem too, the solution is more complex than that.
This comment has been hidden.
+
and/
aren't alphanumeric.Oops, I glossed over thar-thanks!
This comment has been hidden.
you should go read up on 'Regular Expressions' to give yourself some context on what this is asking you to do. Then come back and attempt any 'Regexp basics' kata to build some skill on it. i was exactly where you are last week and now i understand this a lot better lol
I am having trouble with this one. I wrote regex to account for all the requirements(including alphanumeric). When I submit my solution, all my tests pass except for one. When I check the console.log() of the return statement... it says False... but still there is the error: Expected Falso.
Can someone help with this?
in this case, you may possibly be reading the logs off by one. (the log appears above the test result)
"Expected false Log false "
I am reading the correct message for the test result.. still it's not working.
The log of one test appears above that test result.
@Chrono79, above that test result is another test result that is working. See below:
Test Passed Log true
Expected false Log false
All the Sample tests have worked in my code editor. I am stuck here. Can anyone help?
Well, you can
console.log(password)
and see which one is failing. And, if you want, there are many online tools that can validate your regex with that input.A single test is like this:
First the log, then the test result.
This comment has been hidden.
From description:
Which means that dot and semi-colon are invalid characters.
this is my first time when I used regular expressions, it was very difficult in the beginning and much easier in the end)
It's nice to have some regex practice, I feel this skill can easily go neglected.
This comment has been hidden.
probably not a problem with the JavaScript code; it has 6,319 completions. if you have a specific question someone may be able to help you.
This comment has been hidden.
I feel similarly disappointed that the submission tests in Shell do not give any feedback on which passwords are being tested.
Looks like you may need to consider illegal leading and trailing characters.
Whether underscore is considered alphanumeric (as regex treats it) or not (as we would colloquially treat it) should be clarified in the instructions.
This comment has been hidden.
I have the same problem.
This comment has been hidden.
Thanks.
This comment has been hidden.
not an issue, this code just doesn't match the specifications.
This comment has been hidden.
That one expects
true
you're confusing it with the next or the previous one, the log appears above the test result.Thanks!
This comment has been hidden.
This comment has been hidden.
Normally yes, depends on the length of the output, in that case
Test.expect
with a meaningful error message is the way to go. If the returned value is a booleanTest.expect
is ok too.Thanks, but in the above issue I reported it must be using something different because it only says
Expected false
.In that case, the default error message of
Test.assertEquals
would sayExpected: false, instead got: true
is that any better?No, but of course someone could change it so it would say what value got passed in to the function. That's the main thing, because if it just says something didn't pass the test doesn't tell you anything about why it didn't because you've got no info.
This comment has been hidden.
Thanks! Just curious why you marked it as spoiler? doesn't look like a spoiler to me. Also, what do you mean by 'overrated'?
This comment has been hidden.
yes, I think 6 kyu would be better. Was fairly easy for me anyway, and I can't solve most 5 kyu problems :/
I've added this test
Test.expect(!validate('fjd3 IR9'), 'fjd3 IR9 - Expected false');
and it passes in sample tests, but it's failing after attempt phase. I think it's some kind of a bug here.putting it into the sample tests doesn't put it into the attempt phase tests ;)
I know ... I just copied password from
console.log
and expect result to be false like in attempt phaseThis comment has been hidden.
This comment has been hidden.
This comment has been hidden.
.
matches any char, so you'll probably'll have to change that. You'll have to fix more than that tho, check the instructions again about the password criteria.This comment has been hidden.
Why do the password 'djI38D55'and 'fjd3 IR9' expect 'false'? Aren't they valid? They're the only test I can't pass
What language are you attempting to solve the problem in? This will help others who have completed it before ensure that the behavior you're describing is reflected in the code (since it shows the assessment code after the kata has been completed).
To answer your question though, 'djI38D55' is supposed to evaluate as true, but 'fjd3 IR9' should evaluate as false. This is due to the second one containing a space, which is NOT an alphanumeric character. I can definitely understand the confusion though, as many password validation tools these days actually allow the usage of spaces. However, this kata specifies otherwise in the rules.
If you're doing this problem in python, the test cases are behaving correctly. Otherwise, if you're doing this in another language, let me know, and I can check if the tests are correct.
Sorry, I was looking at the wrong row, it's not 'djI38D55' but 'fjd3IR9.;'. You already answered my question btw, I didn't read the rules properly, thank you!
All basic tests I passed, but for random tests I got several 'failed'
For example "!odB?gjkB5a". In this case should be 'False' and in my IDE I got this 'False', but test shows "It should work for random inputs too: True should equal False"
'looks like you solved it'
This comment has been hidden.
TRY BELOW METHOD regex="put your regex expression" def search(regex,a): your logic return t/f
and in regex="put your regex expression"
This comment has been hidden.
Use
console.log
and print the input. It's shown above the test result.Thanks
In the question say that it should be alphanumeric, apply it and makes work for me
Can anyone explain me the steps on how to
console.log
the test cases? ThanksThis comment has been hidden.
This comment has been hidden.
;)
my code works perfectly on idle whether it a function or not but here it doesnt work
Same problem here. Idle works, but here I get a False output every time.
This comment has been hidden.
done
This comment has been hidden.
Use proper markdown so we can see the real code you used. Try printing the input to the console so you check why your code fails.
This comment has been hidden.
This comment has been hidden.
Check how to use proper markdown to see the real code you pasted there
This comment has been hidden.
The last part is wrong, hope that's enough for you to fix it. Check your regular expression here: regex101.com
Got it
Need to add a test case for
\w
, since the description explicitly asks for alphanumeric. Or just add random tests, since one could pass this with a simple counter.fixed
This comment has been hidden.
Yeah, because apparently people used to love to use
.to include
a real lot. It's always mysterious to me what were people even thinking back at the early CW days...Changed to
.to eq
.This comment has been hidden.
done
This comment has been hidden.
Your code didn't fail at
abc
, it fails atfjd3IR9.;
.thx. I thought that is 7th test with abc
I passed all tests except 7th('abc'). In IDE result is false, have to pass it in tests. Some issue in tests?
"I can't pass the tests" is not an issue, but a
question
;-)If you want others to review your code you can post your code formatted and marked as spoilers.
This comment has been hidden.
assuming it's the same 7th tests than in the python version:
'fjd3IR9.;'
Use
console.log("*" + someVar + "*")
to print the input value, the asterisks are there so you can see leading and trailing spaces. Note that the log message comes before the test result.P.D.: that doesn't help in this case.
@chrono: except that there is no var to print ;) ("pure" regex problem... with bad test setup, not displaying the string tested... :/ )
I should have checked that first :P Well, at least I can confirm that's the input in js too for 7th test.
This comment has been hidden.
"I can't pass the tests" is not an issue ;-)
the distribution of awk on the server is mawk not gawk, and it seems that there is no gawk installed on the server.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
use Regex
Hi. You don't need to enter actual code for this kata. You just need to put a regex expression in the "regex" portion of the answer.
Javascript. This password #@%%♥♧☼djI38D55 passed test. The test is performed if at the beginning of the password are not alphanumeric characters.
This comment has been hidden.
This comment has been hidden.
You don't need to write a function, only the var
regex
content (a regular expression string), a functionsearch
is already in the test set and will be used it to generate the output.Marked as resolved.
i have the same problem and i remove the function but still didn't understand how to get inputs?
This comment has been hidden.
You're supposed to write a regex, not create a function.
Not a kata issue.
This kata is horrible in it's current state. Here's some constructive feedback:
For everybody who's having problems with this kata, here's what your function needs to do:
If these requirements are not met, your functions needs to return false.
.
The special characters were tough for me, but I finally got it! Great regex practice!
This comment has been hidden.
probably because of naming. Try to use the same function name and it's parameter, like in kata, and NOT your own.
In Python and Ruby you should only set the regex var value, you can't control what the tests do. Not a kata issue.
I faced a bug in test case: The test with "dsF43" password, which is valid, I think, supposed to be false. Why so?
6 characters req.
It is important suggestion. I missed it!
Also can any one tell how would it be if we wanted to match each condition some 'n' number of times?
This comment has been hidden.
It doesn't guarantee at least one of each kind, so
"aaaaaa"
and such will pass that regexFinally I passed. Read requirement again and again. ^_^
This comment has been hidden.
This comment has been hidden.
I'm new to regex, but it seems that you don't allow for a reoccurrence of any letters or numbers.
For example: "(?=.[a-z])" returns the first instance of any lowercase letter, but does not allow for duplicates.
"(?=.*[a-z])" returns the first instance of any lowercase letter, but the asterisk symbol allows for 0 to infinite repititions.
When I modified my code that passed all tests to remove the asterisk symbol so it look like yours, my test failed. Also, you should (from what I've read) place the "{6,}" after the "(?=.\d)" and add a "$" at the end to tell regex that the string is done (good habits to reduce errors when dealing with multiline comments if you ever do). Hopefully this helped!
Issues are for problems in the kata, not problems in your solution.
The tests and the instructions aren't consistent. A test should be added to check if underscore is allowed in a password. It shouldn't be, because the input says alphanumeric only. But many solutions use \w (includes underscore) and still pass all tests.
This comment has been hidden.
I'm a bit lost here. Can someone give me a tip where I can read up on regex""? I checked python.org/2/library/re.html, but honestly, that was overwhelming and not very helpful.
As far as I understood regex is some sort of matching algorithm that checks strings against strings (like I give it the parameter 'A' and a string and it checks if 'A' is in that string. Is that correct?
Hi iphark. For this particular kata, research "lookahead assertion", "character set", and how the ^ (carat) and $ (dollar sign) work in regex. Hopefully this helped!
View these discussions, I have better understanding what the author wants. The regular expression. I will have a try.
This comment has been hidden.
You're supposed to do a regex variable named "regex" here, not a function. Thus of course your code won't be called ^^
Helpful Kata to have bookmarked -- be sure and check for any non-alphanumeric results!
Transalation created for Bash Here
This comment has been hidden.
This comment has been hidden.
There is a space in that password, which is not alphanumeric (=not a letter, not a number) and you don't filter it out.
Please link your source (CheckiO or any other website).
It would have liked some clarification on whether _ (underscore) is considered "alphanumeric". Many solutions use \w, and others use [a-zA-Z0-9]. None of the tests include the underscore, so there's no way to tell whether it's permitted or not. However, each requires a different regex.
This comment has been hidden.
You can print the input to the console to see where you went wrong. You seem to be failing these two tests:
Test.expect(!validate('fjd3IR9.;'), 'Expected false'); Test.expect(!validate('fjd3 IR9'), 'Expected false');
The Kata test cases are correct so I think you need to double check your code. Without seeing your code I can't directly comment on why you failed but I assume it's because you are allowing non-alphanumerical characters to pass. If you need any help, just shout me.
This comment has been hidden.
Java translation created
Author, please add the alphanumeric condition as a bullet point, everyone is getting tripped up either not looking at the condition or thinking you are implying that you can assume the test will only supply alphanumeric values.
i've passed all the tests but failed 1 condition when submit?
Ruby and Python translations submitted (let me know if you cannot see both of them), if you wish to approve them.
Also, note how I set the kata to force users to really use just a regex: I hope that's what you really expected :)
Yeah, the instructions/tests should be clearer on the "one and only one" regex thing.
The JavaScript version allows multiple.
You should add a test case to check if people are using one and only one regex ( and a good one not a kilometric ). The only way I can think now is by adding a performance test. I've done it on Java but don't really know how it can be done on javascript. Please check the test cases for this kata.
No reason to do this
Also, one regex can be slower than multiple regex. Not sure where you got the idea that regex performance depended only on quantity instead of complexity.
And it is fairly easy to test solution composition, the test cases obviously have access to them...
Javascript version of Kata could ideally include randomly generated passwords (valid and invalid alike); keep that in mind when authoring future Kata :)
Kata description states: "Valid passwords will only be alphanumeric characters." I have not found in description if _ symbol (underline) is allowed in passwords or should be excluded. Your tests do not cover this issue either. \w includes A-Z, a-z and 0-9 as well as underline. Some accepted solutions use \w token. Please modify description/tests.
This comment has been hidden.
\d
is the same as[0-9]
"Test Failed: Expected false"
Without more information on why the "Submit" test is false, it's hard to know why my solution (that passes all the "Test" tests) isn't valid.
I didn't want anyone to cheat and have the method just return what the solution's tests look for. Probably unncessary, but I completed a 2 kyu problem with that method once, and I didn't want anyone circumventing my kata with that. I see you have a working solution now. Do you know what the issue was?
I had missed the "Valid passwords will only be alphanumeric characters." part. (Which unfortunately isn't a bullet point in the description.)
I disagree with you on the "cheat" thing, but if you fear people might just exactly match things, there are several ways you can improve the kata:
I have the very same problem - passed the test but when submiting, I am getting one fail without any feedback on how the test actually failed
This is a fine kata for testing basic regular expression usage, but I do worry that it encourages the idea that passwords should disallow non-alphanumeric characters. In reality, this is an anti-pattern that makes passwords less secure.
http://xkcd.com/936/
@Osuushi That may be true in real-world applications, but I don't think this kata is trying to teach that particular point. I think it's more trying to get us to think about how to write more seemingly complex regexes for testing things that would be trivial with if/elses.
@Eric Interesting point. Didn't know about that.
@wthit56: In this case, regex is the way to go, since you're going to need regexes for each of the conditions anyway, and putting them into one regex doesn't add to the complexity at all. You could go with 4 different regexes (optionally a length check), if you wanted, and 'chain' the result of each test with
&&
, but that's pretty much the same thing as doing it in one regex, only slower. Using a singular regex is less readable, though, I'll give you that.As a bonus, though, you can use pretty much the same regex in html5 form validation* and in your server-side validation.
*
<input pattern="...">
Whole point of writing code using high level languages is to improve readability. Abstraction helps humans. While it may be fun to try and do everything with one-liners, some people are here to learn and share. When the top solution is too convoluted, people have a much harder time learning and sharing.
It might be a better idea to simply accept a string in a designated variable, which should contain the regex source. As it is, there's nothing to stop people just using if/else, etc., thereby completely ignoring the point of the kata.
The test should make sure the single regular expression is created and used. Maybe: "make a function that returns regexp that validates passwords in such and such way", then the function should create and return a regexp object. Of course that will invalidate all existing solutions, but it doesn't matter imho.
That's a good idea. I thought I was being pretty blunt by writing everything but the regex for the user, but I still see multiple solutions that use several regex statements strung together and one that doesn't even use regex at all! I'll look into updating the kata this evening.
@EricFreeman - I see this was a quite long evening, since I've just uploaded solution that uses multiple regexes :)