3

Consider the following Text:

Lorem ipsum dolor sit amet, eum ut vitae quidam mentitum, eu eum malorum eligendi tincidunt. Vix te vitae tamquam, mea nisl praesent ea, vis omnis postulant in

import sys def fun(){print('Hello')} fun()

Mea veri fierent explicari eu, ne appareat convenire mei. Dicat neglegentur definitiones nec id, sit facete cotidieque in. Intellegam referrentur cu cum, an mandamus periculis pro.

Stack Overflow throws an error related to indentation, if the code is not formatted well. Like this:

(Image source)

How does it determine that unformatted code exists?

6
  • 2
    Are you asking how Stack Overflow detects unformatted code inside a question? Or are you asking someone to write code for you that detects code snippets inside a string?
    – Rizier123
    Apr 6, 2017 at 13:31
  • 5
    From the developer who coded that piece: "nothing that fancy. We run through lines that look like code (some regex + keyword checking) and verify how many of them start with 4 consecutive spaces" Apr 6, 2017 at 13:41
  • @ryanyuyu Not a duplicate. That asks about how to format, where as this is how does the SE Broken Code Detectorâ„¢ work. Apr 6, 2017 at 13:53
  • @Kendra Yes, this is a challenging problem and it is really difficult to parse. I was thinking in the lines of AI or Machine Learning to solve this. Apr 6, 2017 at 13:59
  • I misunderstood the question. I edited it to match Rizier's comment about how SO produces that warning in the editor.
    – ryanyuyu
    Apr 6, 2017 at 14:01
  • @Rizier123 In a broad sense, both. I want to understand the logic for detecting code snippet inside a string. Also, Stackoverflow detects unformatted code in a string. How does it do that? Apr 6, 2017 at 14:04

0

You must log in to answer this question.

Browse other questions tagged .