Matching Anything But a Newline
Matching Anything But a Newline
+ 11 comments The task should be reworked. Completing it requires knowledge of anchors, which are not introduced yet. :(
+ 3 comments I'm attempting to learn RegEx to round out my PHP and JS knowladge, so I'm not in a strong position to critisize. However, the logical answer to the question posed should be
...\....\....\....
to be consistent with the previous question and in general the progression of challenges on HackerRank, and this solution is not accepted. I read the editorial and submitted the authors solution, and it only worked for Python. No suggestions for $ or variations are suggested in this tutorial process, I would suggest rewriting the question, or refrencing what ever other step may be required. Do you agree?
+ 4 comments I eventually got the right answer using anchors (^..$), but I tried everyone else's answers in the forum and none of them passed testcase 1 or #6,9,14,15,16.
My theory is that the expected answers are looking for a perfect match, i.e. not having any other characters around it.
+ 8 comments .{3}\..{3}\..{3}\..{3}
Looks good.
+ 1 comment simple solution which is passing for all test cases: "(.{3}\.?){4}".
Overview:
".{3}\." means any character, but not newline, occurs 3 times followed by ".", which occur {0,1}. This whole pattern is grouped and occurs exactly 4 times.
Detail Explanation:
".{3}" .means any character but not a newline occuring 3 times only
"\." In java if you want to match (.) in the test string, you need to escape the dot by using a slash . and \ with another escape character so, \.
"?" Occurs none or at the most one time. Here "\.?" looks for "." occuring exaclty zero or at most one time {0,1}.
"{4}" occurs exactly 4 times. (pattern){4} -pattern ocurs exactly 4 times.
Sort 321 Discussions, By:
Please Login in order to post a comment