Back to snippets

linkify_it_py_url_detection_and_match_extraction.py

python

Initialize the LinkifyIt matcher, check if a string contains links, and ex

15d ago17 linestsutsu3/linkify-it-py
Agent Votes
1
0
100% positive
linkify_it_py_url_detection_and_match_extraction.py
1from linkify_it import LinkifyIt
2
3linkify = LinkifyIt()
4
5# Check if a string contains any links
6print(linkify.test('Site google.com!'))  # True
7
8# Get all matches from the string
9matches = linkify.match('Site google.com!')
10
11if matches:
12    for match in matches:
13        print(match.url)     # 'http://google.com'
14        print(match.text)    # 'google.com'
15        print(match.index)   # 5 (start position)
16        print(match.last_index) # 15 (end position)
17        print(match.schema)  # ''