Example
Input:
<p><a href="http://www.quackit.com/html/tutorial/html_links.cfm">Example Link</a></p>
<div class="more-info"><a href="http://www.quackit.com/html/examples/html_links_examples.cfm">More Link Examples...</a></div>
# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
import sys
text = sys.stdin.read()
pattern = r'<(\w+)'
import re, sys
print(';'.join(sorted(set(re.findall(pattern, text)))))
Explanation
The first line contains 2 tag names: p and a.
The second line contains 2 tag names: div and a.
Our set of unique tag names is: p a div
When we order these alphabetically and print them as semicolon-separated values, we get “a;div;p”.
Test cases
Input
<p><a href="http://www.quackit.com/html/tutorial/html_links.cfm">Example Link</a></p>
<div class="more-info"><a href="http://www.quackit.com/html/examples/html_links_examples.cfm">More Link Examples...</a></div>
Output
a;div;p
Source: https://yellorn.com/programming/regex-detect-html-tags
Comments
Post a Comment