Regex | Programming Language Name

Source: https://yellorn.com/programming/regex-programming-language-name

C:CPP:JAVA:PYTHON:PERL:PHP:RUBY:CSHARP:HASKELL:CLOJURE


ERLANG:CLISP:LUA:BRAINFUCK:JAVASCRIPT:GO:D:OCAML:R


GROOVY:OBJECTIVEC:BASH:SCALA:PASCAL:SBCL:DART


Sometimes, error-prone API requests can have an invalid language field. Could you find out if a given submission has a valid language field or not?

Input Format

First-line contains N. N API requests follow, each in a new line. Each request has an integer api_id and a string language which are the request parameters placed by the API request.

**Constraints**

```
1 <= N <= 100  
10^4 <= api_id < 10^5  
```

a valid language is any of the languages listed above (case sensitive):

Output Format

For every api request given in input, print “VALID” if it has a valid language string in it or print “INVALID” otherwise.

Explanation

LUA and BRAINFUCK are valid languages as listed above. As X is doesn’t appear in the list, it is an invalid request.

Testcase

Input

3
11011 LUA
11022 BRAINFUCK
11044 X

Output

VALID
VALID
INVALID

Solution

import re
import sys

pattern = r"\b(?:C|CPP|JAVA|PYTHON|PERL|PHP|RUBY|CSHARP|HASKELL|CLOJURE|BASH|SCALA|ERLANG|CLISP|LUA|BRAINFUCK|JAVASCRIPT|GO|D|OCAML|R|PASCAL|SBCL|DART|GROOVY|OBJECTIVEC)\b"
for _ in range(int(input())):
    text = sys.stdin.readline()
    found = re.search(pattern, text)
    print('VALID' if found else 'INVALID')

Comments