Server IP : 85.214.239.14 / Your IP : 3.149.242.223 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/3/task/3/cwd/srv/modoboa/env/lib/python3.5/site-packages/phonenumbers/ |
Upload File : |
"""Additional regular expression utilities, to make it easier to sync up with Java regular expression code. >>> import re >>> from .re_util import fullmatch >>> from .util import u >>> string = 'abcd' >>> r1 = re.compile('abcd') >>> r2 = re.compile('bc') >>> r3 = re.compile('abc') >>> fullmatch(r1, string) # doctest: +ELLIPSIS <...Match object...> >>> fullmatch(r2, string) >>> fullmatch(r3, string) >>> r = re.compile(r'\\d{8}|\\d{10,11}') >>> m = fullmatch(r, '1234567890') >>> m.end() 10 >>> r = re.compile(u(r'[+\uff0b\\d]'), re.UNICODE) >>> m = fullmatch(r, u('\uff10')) >>> m.end() 1 """ import re def fullmatch(pattern, string, flags=0): """Try to apply the pattern at the start of the string, returning a match object if the whole string matches, or None if no match was found.""" # Build a version of the pattern with a non-capturing group around it. # This is needed to get m.end() to correctly report the size of the # matched expression (as per the final doctest above). grouped_pattern = re.compile("^(?:%s)$" % pattern.pattern, pattern.flags) m = grouped_pattern.match(string) if m and m.end() < len(string): # Incomplete match (which should never happen because of the $ at the # end of the regexp), treat as failure. m = None # pragma no cover return m if __name__ == '__main__': # pragma no cover import doctest doctest.testmod()