Detect HTML Tags

Sort by

recency

|

149 Discussions

|

  • + 0 comments

    Python:

    import re; html = "\n".join([input() for _ in range(int(input()))]); print(";".join(sorted(set(re.findall(r"<\s?([a-zA-Z]+[0-9A-Za-z])[^>]>", html)))));

  • + 0 comments

    Perl

    use List::Util qw( uniq );
    BEGIN{$, = ";"};
    
    my @allmatch;
    while(<>){
        chomp;
        my @matches = m|<([^\s/]+?)[>\s]|g;
        push @allmatch, @matches;
    }
    my @res = uniq(sort(@allmatch));
    
    print @res;
    
  • + 0 comments
    import re
    pattern =  r'<(\w+)>?'
    lst = []
    
    for i in range(int(input())):
        m = re.findall(pattern, input())
        for i in m:
            if i not in lst:
                lst.append(i)
    print(';'.join(sorted(lst)))
    
  • + 1 comment

    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 = scanner.nextInt(); scanner.nextLine();
            //one or more spaces before tagname. So \\s*
            Pattern pattern = Pattern.compile("<\\s*(\\w+)[^>]*>");
            TreeSet<String> tags = new TreeSet<String>();
            for(int i=0;i<n;i++)
            {   Matcher matcher = pattern.matcher(scanner.nextLine());
                while(matcher.find())   tags.add(matcher.group(1));
            }
            System.out.println(String.join(";",tags));
        }
    }
    
  • + 0 comments

    Javascript solution

    let tags = input.match(/(?<=\<)[^\s>\/]+(?=[\s>])/g)
    tags = tags.filter((x, i, a) => a.indexOf(x) == i)
    console.log(tags.sort().join(';'))