Coverage for portality/regex.py: 89%
19 statements
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-22 15:59 +0100
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-22 15:59 +0100
1import re
3#~~DOI:Regex~~
4DOI = r"^((https?://)?((dx\.)?doi\.org/|hdl\.handle\.net/)|doi:|info:doi/|info:hdl/)?(?P<id>10\.\S+/\S+)$"
5DOI_COMPILED = re.compile(DOI, re.IGNORECASE)
7#~~ORCID:Regex~~
8ORCID = r"^https://orcid\.org/[0-9]{4}-[0-9]{4}-[0-9]{4}-\d{3}[\dX]$"
9ORCID_COMPILED = re.compile(ORCID)
11#~~ISSN:Regex~~
12ISSN = r'^\d{4}-\d{3}(\d|X|x){1}$'
13ISSN_COMPILED = re.compile(ISSN)
15#~~Date:Regex~~
16BIG_END_DATE = r'^\d{4}-\d{2}-\d{2}$'
17BIG_END_DATE_COMPILED = re.compile(BIG_END_DATE)
19#~~URL:Regex~~
20HTTP_URL = r'^https?://([^/:]+\.[a-z]{2,63}|([0-9]{1,3}\.){3}[0-9]{1,3})(:[0-9]+)?(\/.*)?$'
21HTTP_URL_COMPILED = re.compile(HTTP_URL, re.IGNORECASE)
24def is_match(pattern, string, *args, **kwargs):
25 match = re.match(pattern, string, *args, **kwargs)
26 return match is not None
29def group_match(pattern, string, name, *args, **kwargs):
30 match = re.match(pattern, string, *args, **kwargs)
31 if match is None:
32 return None
33 return match.group(name)