Skip to content

andytzeng/pyxurls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyXURLs

PyPI version Build Status PyPI - Python Version

A regular expression based URL extractor which extracts URLs from text.

Thanks to Daniel Martí invests the project mvdan/xurls. This python project developed by the same concept as the golang version.

Installing

# the alternative is regex as engine if you suffered installing on re2
pip install google-re2 pyxurls

Usage

Extract URLs by strict strategy

import xurls

extractor = xurls.Strict()

url = extractor.findfirst('we have the link with scheme https://www.python.org and https://www.github.com')
#  https://www.python.org

urls = extractor.findall('we have the link with scheme https://www.python.org and https://github.com')
#  ['https://www.python.org', 'https://github.com']

Extract URLs by relaxed strategy

import xurls

extractor = xurls.Relaxed()

url = extractor.findfirst('we have the link with scheme www.python.org and https://www.github.com')
#  www.python.org

urls = extractor.findall('we have the link with scheme www.python.org and https://github.com')
#  ['www.python.org', 'https://github.com']

Extract URLs by limit scheme

import xurls

# limit to https
extractor = xurls.StrictScheme('https://')

url = extractor.findfirst('we have the link with scheme custom://domain.com and https://www.python.org noscheme.com')
#  https://www.python.org

# unlimit to standard scheme
extractor = xurls.StrictScheme(xurls.express.ANY_SCHEME)
urls = extractor.findall('we have the link with scheme custom://domain.com and https://www.python.org noscheme.com')
#  ['custom://domain.com', 'https://www.python.org']

About

A regular expression based URL extractor which extracts URLs from text.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages