Building a Smart IDE: Programming Language Detection Discussions | Regex | HackerRank

Building a Smart IDE: Programming Language Detection

  • + 0 comments

    Python 3

    import re
    import sys
    string = sys.stdin.read()
    if bool(re.findall(r'\bdef\b|[^\.]print\b', string)):
        print("Python")
    elif bool(re.findall(r"\bpublic\s+class\b|\bpublic\s+static\s+void\s+main\b|\bSystem\.out\.println\b", string)):
        print('Java')
    elif bool(re.findall(r'\b#include\b|\bint\s+main\b|\bprintf\b', string)):
        print('C')