We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Regex
  3. Introduction
  4. Matching Anything But a Newline
  5. Discussions

Matching Anything But a Newline

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 321 Discussions, By:

votes

Please Login in order to post a comment

  • Epigene
    6 years ago+ 11 comments

    The task should be reworked. Completing it requires knowledge of anchors, which are not introduced yet. :(

    174|
    Permalink
    View more Comments..
  • alex_c_freeman
    5 years ago+ 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?

    39|
    Permalink
  • catsarenotfood
    6 years ago+ 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.

    15|
    Permalink
    View more Comments..
  • eapmartins
    6 years ago+ 8 comments

    .{3}\..{3}\..{3}\..{3}

    Looks good.

    12|
    Permalink
    View more Comments..
  • saisaripalli
    6 years ago+ 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.

    11|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature