Package: regxon
RegXonRegXon is a powerful validator, sanitizer and content parser that you're searching for decades.InstallationpipinstallregxonUsagefromregxon.commonimportRegxonregxon=Regxon()General ValidationGeneral validation includes email, domain, url and ipv4.Validate Emailfromregxon.commonimportRegxonregxon=Regxon()regxon.is_email('xyz@.com')# Noneregxon.is_email('xyz@cpx.com')# returns a proper Match object; you can grab the match with `.string`Validate Domainfromregxon.commonimportRegxonregxon=Regxon()regxon.is_domain('xyzcom')# Noneregxon.is_domain('xyz.com')# returns a proper Match object; you can grab the match with `.string`Validate URLfromregxon.commonimportRegxonregxon=Regxon()regxon.is_url('xyz.com')# Noneregxon.is_url('https://xyz.com')# returns a proper Match objectValidate HTTP URLfromregxon.commonimportRegxonregxon=Regxon()regxon.is_http_url('xyz.com')# None; returns None if the url is not httpregxon.is_http_url('ftp://xyz.com')# None; returns None if the url is not httpregxon.is_http_url('http://django.c')# None; returns None because `.c` is not a valid domainregxon.is_http_url('https://xyz.com')# returns a proper Match object; you can grab the match with `.string`Validate IPfromregxon.commonimportRegxonregxon=Regxon()# 1, 2 both are same and return a proper Match, as default schema is ""regxon.is_ipv4('127.0.0.1')# 1regxon.is_ipv4('127.0.0.1',schema='')# 2; matches because 127.0.0.1 has no schemaregxon.is_ipv4('http://127.0.0.1')# returns None as schema is not matched; "http" != ""regxon.is_ipv4('http://127.0.0.1',schema='')# returns None as schema is not matched; "http" != ""regxon.is_ipv4('http://127.0.0.1',schema='http')# returns a proper Matchregxon.is_ipv4('https://127.0.0.1',schema='http')# returns None as schema is not matched; "https" != "http"Validate Phone Numberfromregxon.commonimportRegxonregxon=Regxon()regxon.is_phone('+91 1234567890')# returns a proper Match object; you can grab the match with `.string`HTML Sanitization and ValidationRegXon provides a powerful HTML sanitizer and validator that you're searching for decades.
It's a combination ofhtml5libandbeautifulsoup4.You "how to remove an attribute from HTML tag" problem is solved now. Or
another problem of "how to remove a tag from HTML" is also solved.fromregxon.htmlimportRegxonHTMLregxon_html=RegxonHTML()html_content="""<img onload="alert(1)" onerror="hey" src="http://example.com" /><script>alert(1)</script>"""html=regxon_html.get_sanitized_content(html_content)print(html)The above code will print the following output<imgonerror="hey"/>Add custom excluded attributes for any tag you wantfromregxon.htmlimportRegxonHTMLregxon_html=RegxonHTML()html_content="""<img onload="alert(1)" onerror="hey" src="http://example.com" /><script>alert(1)</script>"""# Add custom excluded attributes for any tag you wantregxon_html.excluded_attributes.update({'img':regxon_html.excluded_attributes['img']+['onerror'],})The above code will print the following output<img/>Purpose of RegXonSanitize HTML; remove unwanted tags and attributes; XSS preventionValidate IP, URL, Domain; SSRF preventionValidate Email; Email spoofing preventionValidate Phone Number; Phone number spoofing preventionLicenseMITContributingPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.AuthorsBishwas BhandarifromWebmatricesAcknowledgementshtml5libbeautifulsoup4RegExr