1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module phonenumbers.phonenumbermatcher</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="phonenumbers.html"><font color="#ffffff">phonenumbers</font></a>.phonenumbermatcher</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="https://github.com/daviddrysdale/python-phonenumbers/blob/dev/python/phonenumbers/phonenumbermatcher.py">phonenumbers/phonenumbermatcher.py</a></font></td></tr></table>
<p><tt>Functionality to match phone numbers in a piece of text</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="re.html">re</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="builtins.html#object">builtins.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="phonenumbers.phonenumbermatcher.html#Leniency">Leniency</a>
</font></dt><dt><font face="helvetica, arial"><a href="phonenumbers.phonenumbermatcher.html#PhoneNumberMatcher">PhoneNumberMatcher</a>
</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="phonenumbers.util.html#UnicodeMixin">phonenumbers.util.UnicodeMixin</a>(<a href="builtins.html#object">builtins.object</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="phonenumbers.phonenumbermatcher.html#PhoneNumberMatch">PhoneNumberMatch</a>
</font></dt></dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="Leniency">class <strong>Leniency</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt><a href="#Leniency">Leniency</a> when finding potential phone numbers in text segments.<br>
<br>
The levels here are ordered in increasing strictness.<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>EXACT_GROUPING</strong> = 3</dl>
<dl><dt><strong>POSSIBLE</strong> = 0</dl>
<dl><dt><strong>STRICT_GROUPING</strong> = 2</dl>
<dl><dt><strong>VALID</strong> = 1</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="PhoneNumberMatch">class <strong>PhoneNumberMatch</strong></a>(<a href="phonenumbers.util.html#UnicodeMixin">phonenumbers.util.UnicodeMixin</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt><a href="#PhoneNumberMatch">PhoneNumberMatch</a>(start, raw_string, numobj)<br>
<br>
The immutable match of a phone number within a piece of text.<br>
<br>
Matches may be found using the find() method of <a href="#PhoneNumberMatcher">PhoneNumberMatcher</a>.<br>
<br>
A match consists of the phone number (in .number) as well as the .start<br>
and .end offsets of the corresponding subsequence of the searched<br>
text. Use .raw_string to obtain a copy of the matched subsequence.<br>
<br>
The following annotated example clarifies the relationship between the<br>
searched text, the match offsets, and the parsed number:<br>
<br>
>>> text = "Call me at +1 425 882-8080 for details."<br>
>>> country = "US"<br>
>>> import phonenumbers<br>
>>> matcher = phonenumbers.<a href="#PhoneNumberMatcher">PhoneNumberMatcher</a>(text, country)<br>
>>> matcher.has_next()<br>
True<br>
>>> m = matcher.next() # Find the first phone number match<br>
>>> m.raw_string # contains the phone number as it appears in the text.<br>
"+1 425 882-8080"<br>
>>> (m.start, m.end) # define the range of the matched subsequence.<br>
(11, 26)<br>
>>> text[m.start, m.end]<br>
"+1 425 882-8080"<br>
>>> phonenumberutil.parse("+1 425 882-8080", "US") == m.number<br>
True<br> </tt></td></tr>
<tr><td> </td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="phonenumbers.phonenumbermatcher.html#PhoneNumberMatch">PhoneNumberMatch</a></dd>
<dd><a href="phonenumbers.util.html#UnicodeMixin">phonenumbers.util.UnicodeMixin</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="PhoneNumberMatch-__eq__"><strong>__eq__</strong></a>(self, other)</dt><dd><tt>Return self==value.</tt></dd></dl>
<dl><dt><a name="PhoneNumberMatch-__init__"><strong>__init__</strong></a>(self, start, raw_string, numobj)</dt><dd><tt>Initialize self. See help(type(self)) for accurate signature.</tt></dd></dl>
<dl><dt><a name="PhoneNumberMatch-__ne__"><strong>__ne__</strong></a>(self, other)</dt><dd><tt>Return self!=value.</tt></dd></dl>
<dl><dt><a name="PhoneNumberMatch-__repr__"><strong>__repr__</strong></a>(self)</dt><dd><tt>Return repr(self).</tt></dd></dl>
<dl><dt><a name="PhoneNumberMatch-__unicode__"><strong>__unicode__</strong></a>(self)</dt></dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>__hash__</strong> = None</dl>
<hr>
Methods inherited from <a href="phonenumbers.util.html#UnicodeMixin">phonenumbers.util.UnicodeMixin</a>:<br>
<dl><dt><a name="PhoneNumberMatch-__str__"><strong>__str__</strong></a>(self)</dt><dd><tt>Return str(self).</tt></dd></dl>
<hr>
Data descriptors inherited from <a href="phonenumbers.util.html#UnicodeMixin">phonenumbers.util.UnicodeMixin</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="PhoneNumberMatcher">class <strong>PhoneNumberMatcher</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt><a href="#PhoneNumberMatcher">PhoneNumberMatcher</a>(text, region, leniency=1, max_tries=65535)<br>
<br>
A stateful class that finds and extracts telephone numbers from text.<br>
<br>
Vanity numbers (phone numbers using alphabetic digits such as '1-800-SIX-FLAGS' are<br>
not found.<br>
<br>
This class is not thread-safe.<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="PhoneNumberMatcher-__init__"><strong>__init__</strong></a>(self, text, region, leniency=1, max_tries=65535)</dt><dd><tt>Creates a new instance.<br>
<br>
Arguments:<br>
text -- The character sequence that we will search, None for no text.<br>
country -- The country to assume for phone numbers not written in<br>
international format (with a leading plus, or with the<br>
international dialing prefix of the specified region). May be<br>
None or "ZZ" if only numbers with a leading plus should be<br>
considered.<br>
leniency -- The leniency to use when evaluating candidate phone<br>
numbers.<br>
max_tries -- The maximum number of invalid numbers to try before<br>
giving up on the text. This is to cover degenerate cases where<br>
the text has a lot of false positives in it. Must be >= 0.</tt></dd></dl>
<dl><dt><a name="PhoneNumberMatcher-__iter__"><strong>__iter__</strong></a>(self)</dt></dl>
<dl><dt><a name="PhoneNumberMatcher-has_next"><strong>has_next</strong></a>(self)</dt><dd><tt>Indicates whether there is another match available</tt></dd></dl>
<dl><dt><a name="PhoneNumberMatcher-next"><strong>next</strong></a>(self)</dt><dd><tt>Return the next match; raises Exception if no next match available</tt></dd></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>NON_DIGITS_PATTERN</strong> = re.compile('(?:\\D+)')<br>
<strong>U_DASH</strong> = '-'<br>
<strong>U_EMPTY_STRING</strong> = ''<br>
<strong>U_PERCENT</strong> = '%'<br>
<strong>U_SEMICOLON</strong> = ';'<br>
<strong>U_SLASH</strong> = '/'<br>
<strong>U_X_LOWER</strong> = 'x'<br>
<strong>U_X_UPPER</strong> = 'X'</td></tr></table>
</body></html>
|