Detect HTML Tags

Sort by

recency

|

151 Discussions

|

  • + 0 comments

    For Python 3:

    import re
    tag_pattern = re.compile(r'<\s*(?!/|!)([A-Za-z][\w\-]*)',re.ASCII)
    
    number_of_lines = int(input())
    unique_tag_names = set()
    for _ in range(number_of_lines):
        html_line = input()
        unique_tag_names.update(tag_pattern.findall(html_line))
        
    print(";".join(sorted(unique_tag_names)))
    
  • + 0 comments

    import re T = int(input())

    pattern = r'\<([A-Za-z0-9]{1,})|\<\s+([A-Za-z0-9]{1,})' tag_set = set()

    while T>0: line = input() pattern_found = re.findall(pattern, line) for p in pattern_found: tag_set.add(p[0]) tag_set.add(p[1]) T-=1

    print(";".join(sorted([tag for tag in tag_set if len(tag) > 0 ])))

  • + 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)))