Sort by

recency

|

127 Discussions

|

  • + 0 comments

    In Python 3:

    N = int(input())
    alien_name = r'^(_|\.)[0-9]{1,}[a-zA-Z]{0,}(_)?$'
    for _ in range(N):
        name = input()
        matched = re.match(alien_name, name)
        if bool(matched):
            print("VALID")
        else:
            print("INVALID")
    
  • + 0 comments

    import re n = int(input()) for _ in range(n): username = input() pattern = r'^[.]\d{1,}[a-zA-Z]*[]?$' if re.search(pattern,username): print("VALID") else: print("INVALID")

  • + 0 comments

    TypeScript or JavaScript

    function main() {
        const regex = /^[_\.][0-9]+[a-zA-Z]*_?$/;
        for (let i = 1; i < inputLines.length; i++) {
            const str = inputLines[i];
            if (regex.test(str)) {
                console.info('VALID');
            } else {
                console.info('INVALID');
            }
        }
    }
    
  • + 0 comments

    perl

    while(<>){
        chomp;
        next if $. == 1;
        /^[_\.]\d+[a-zA-Z]*_?$/ ? print "VALID\n" : print "INVALID\n";
    
  • + 0 comments

    Java 15

    import java.io.*;
    import java.util.*;
    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    public class Solution {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int n=Integer.parseInt(scanner.nextLine());
            Pattern pattern = Pattern.compile("^[_\\.]\\d+[a-zA-Z]*_?$");
            for(int i=0;i<n;i++)
            {   Matcher matcher = pattern.matcher(scanner.nextLine());
                if (matcher.find()) System.out.println("VALID");
                else    System.out.println("INVALID");
            }
        }
    }