Detect HTML Tags

Sort by

recency

|

148 Discussions

|

  • + 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(';'))
    
  • + 0 comments

    java solution

    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("< *(\\w+)[^>]*>");
            SortedSet<String> ans = new TreeSet<>();
            for (int i = 0; i < n; i++) {
                Matcher matcher = pattern.matcher(scanner.nextLine());
                while (matcher.find()) {
                    ans.add(matcher.group(1));
                }
            }
            System.out.println(String.join(";", ans));
        }
    }